home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 60914 / 60914.xpi / chrome / content / personasrotator.js < prev    next >
Text File  |  2010-01-22  |  97KB  |  2,716 lines

  1. ∩╗┐    
  2.     var PersonasRotator = {
  3.  
  4.         personasrotatorurlprefix:'url("',
  5.         personasrotatorurlsuffix:'")',
  6.         personaImagePreName:"personasrotator/",
  7.         databaseResourceSiteName:"chrome://personasrotator/content/personasrotator/",
  8.         openTabURI:"chrome://personasrotator/content/wr.html",
  9.         currentimagefilename:"",
  10.         moouseclickeventx:0,
  11.         moouseclickeventy:0,
  12.         currentpersonapositionvalues:"",
  13.         currentpersonapositionxvalue:0,
  14.         currentpersonapositionyvalue:0,
  15.         currenteventx:0,
  16.         currenteventy:0,
  17.         moveonxpath:0,
  18.         moveonypath:0,
  19.         personasrotator:[],
  20.         imagespecified:"no",
  21.         uploadrequested:"no",
  22.         currentarrayindex:0,
  23.         newimage:new Image(),
  24.         previewtabs:[],
  25.         previewtabscopy:[],
  26.         previewurl:null,
  27.         CTRLpressed:false,
  28.         tabtitle:null,
  29.         personasrotatornewstabopened:"no",
  30.         inmovemode:false,
  31.         STRINGS:null,
  32.         _shell:Components.classes["@mozilla.org/browser/shell-service;1"].getService(Components.interfaces.nsIShellService),
  33.         previewTimer:null,
  34.         PR:Components.classes["@personasrotator/startup;1"].getService().wrappedJSObject,
  35.         
  36.         preload: function (){
  37.         
  38.             PersonasRotator.personaimagesarraymaker();
  39.             
  40.             PersonasRotator.currentarrayindex=PersonasRotator.getCurrentarrayIndex();
  41.             
  42.             PersonasRotator.newimage.src=PersonasRotator.assignFileURIToImage(PersonasRotator.personasrotator[PersonasRotator.currentarrayindex%PersonasRotator.personasrotator.length]);
  43.  
  44.         },
  45.     
  46.         personaimagesarraymaker:function  () {
  47.  
  48.             PersonasRotator.personasrotator=[];
  49.         
  50.             var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getlibraryfileURI());    
  51.             
  52.             var container=PersonasRotatorRDF.rdfContainerUtils.MakeSeq(ds,PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator:library"));
  53.             var genericpersonasseqenumurator=container.GetElements();
  54.             var namePredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#name");
  55.  
  56.             while (genericpersonasseqenumurator.hasMoreElements()) {
  57.         
  58.                 var collection=genericpersonasseqenumurator.getNext();
  59.                 
  60.                 var nametarget=ds.GetTarget(collection,namePredicate,true);
  61.             
  62.                 if (nametarget) {
  63.                     
  64.                     var name = nametarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  65.  
  66.                 }
  67.                 
  68.                 var currentcollectionname=name;
  69.                 
  70.                 var collectionContainer=PersonasRotatorRDF.rdfContainerUtils.MakeSeq(ds,PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator:"+PersonasRotator.createEncodedName(currentcollectionname)+"backs"));
  71.                 
  72.                 var genericpersonaslienumurator=collectionContainer.GetElements();
  73.                 
  74.                 var locationPredicate=PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#location");
  75.                 
  76.                 while (genericpersonaslienumurator.hasMoreElements()) {
  77.                     
  78.                     var genericpersonas=genericpersonaslienumurator.getNext();
  79.                     
  80.                     var imagelocationtarget=ds.GetTarget(genericpersonas,locationPredicate,true);
  81.  
  82.                     var imagelocation = currentcollectionname+"/Personas/"+imagelocationtarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  83.                 
  84.                     PersonasRotator.personasrotator.push(imagelocation);
  85.                     
  86.                 }
  87.  
  88.             }        
  89.  
  90.         },
  91.         
  92.         getlibraryfileURI : function () {
  93.  
  94.             var file = Components.classes["@mozilla.org/file/directory_service;1"]
  95.                      .getService(Components.interfaces.nsIProperties)
  96.                      .get("ProfD", Components.interfaces.nsIFile);            
  97.             
  98.             file.append("personasrotator");
  99.             
  100.             file.append("library.rdf");
  101.             
  102.             var ios = Components.classes["@mozilla.org/network/io-service;1"]
  103.                                 .getService(Components.interfaces.nsIIOService);
  104.                                 
  105.             var URL = ios.newFileURI(file);
  106.             
  107.             return URL.spec;
  108.  
  109.         },
  110.         
  111.         writelastimageindex:function (event) {
  112.  
  113.             PersonasRotatorFileIO.write(PersonasRotator.getChromeFile("config.abc"),PersonasRotator.currentarrayindex,'w',"UTF-8"); 
  114.  
  115.         },
  116.  
  117.         getChromeFile:function(filename) {
  118.         
  119.             if (filename==undefined || filename==null )    return;
  120.             
  121.             var namesplitarray=filename.split("/");
  122.  
  123.             var file = Components.classes["@mozilla.org/file/directory_service;1"]
  124.                                  .getService(Components.interfaces.nsIProperties)
  125.                                  .get("ProfD", Components.interfaces.nsIFile);
  126.  
  127.             file.append("personasrotator");
  128.             
  129.             for (var i=0;i<namesplitarray.length;i++) {
  130.             
  131.                 file.append(namesplitarray[i]);
  132.             
  133.             }
  134.             
  135.             return file;
  136.  
  137.         },
  138.         
  139.         getCurrentarrayIndex:function() {
  140.             
  141.             var currentIndex;
  142.                     
  143.             var indexes=PersonasRotatorFileIO.read(PersonasRotator.getChromeFile("config.abc"),"UTF-8");
  144.             
  145.             if (indexes.indexOf(",")==-1) {
  146.             
  147.                 currentIndex=parseInt(indexes);
  148.             
  149.             }
  150.             
  151.             else {
  152.             
  153.                 var splitArray=indexes.split(",");
  154.             
  155.                 var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
  156.                 
  157.                 var enumerator = wm.getEnumerator("navigator:browser");
  158.                 
  159.                 var win = null;
  160.                 
  161.                 var winarray=[];
  162.                 
  163.                 while (enumerator.hasMoreElements()) {
  164.                 
  165.                     win = enumerator.getNext();
  166.                     
  167.                     winarray.push(win);
  168.                     
  169.                 }
  170.                 
  171.                 currentIndex=splitArray[winarray.length-1];
  172.                         
  173.             }
  174.                 
  175.                 return !isNaN(currentIndex) ? currentIndex : 0;
  176.             
  177.         },
  178.         
  179.         assignFileURIToImage:function(filename){
  180.             
  181.             if (filename==undefined || filename==null )    return;
  182.         
  183.             var file=PersonasRotator.getChromeFile(filename);
  184.  
  185.             var ios = Components.classes["@mozilla.org/network/io-service;1"]
  186.                                 .getService(Components.interfaces.nsIIOService);
  187.                                 
  188.             var URL = ios.newFileURI(file);
  189.  
  190.             return URL.spec;
  191.         
  192.         },
  193.         
  194.         mainWindowLoadHandler:function(event) {
  195.         
  196.             PersonasRotator.instalandupdatecheck();
  197.         
  198.             gBrowser.addEventListener("DOMContentLoaded",PersonasRotator.aboutblanklistener,true);
  199.             
  200.             document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", PersonasRotator.handlepop, false);
  201.             
  202.             PersonasRotator.tabtitle=document.getAnonymousElementByAttribute(document.getElementById("content"), "anonid", "tbstringbundle").getString("tabs.untitled");
  203.         
  204.             //window.document.addEventListener("keydown",PersonasRotator.CTRLKeydownListener,false);
  205.             //window.document.addEventListener("keyup",PersonasRotator.CTRLKeyupListener,false);
  206.             
  207.             //PersonasRotator.bringPersonas();
  208.  
  209.             //URLBarSetURI = PersonasRotator.newURLBarSetURI;
  210.             
  211.             //PersonasRotator.requestDesktopPersonaChange();
  212.             
  213.             PersonasRotator.STRINGS=document.getElementById("personasrotator-strings");
  214.  
  215.             
  216.         },
  217.         
  218.         instalandupdatecheck:function ()  {
  219.  
  220.             var personasrotatorprefsinstance = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  221.             var personasrotatorversion = personasrotatorprefsinstance.getCharPref("extensions.personasrotator.currentversion");
  222.             var personasrotatoretensionmanagerinstance = Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager);
  223.             var personasrotatorextension = personasrotatoretensionmanagerinstance.getItemForID("{6e73f6b7-b9ab-44b8-b744-6393e3c2e351}");
  224.             var personasrotatornewversion = personasrotatorextension.version;
  225.  
  226.             if (personasrotatorversion != personasrotatornewversion) {
  227.                         
  228.                 personasrotatorprefsinstance.setCharPref("extensions.personasrotator.currentversion",personasrotatornewversion);
  229.             
  230.                 gBrowser.addEventListener('load',PersonasRotator.personasrotatorFirstRun, true);
  231.                             
  232.             }
  233.         
  234.         },
  235.  
  236.         personasrotatorFirstRun:function  () {
  237.             
  238.             gBrowser.removeEventListener('load', PersonasRotator.personasrotatorFirstRun, true);
  239.  
  240.             var personasrotatorprefsinstance = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  241.             var personasrotatorinstalled =personasrotatorprefsinstance.getBoolPref("extensions.personasrotator.installed");
  242.             var personasrotatorUrl;
  243.  
  244.             if (!personasrotatorinstalled) {
  245.                 
  246.                 personasrotatorprefsinstance.setBoolPref("extensions.personasrotator.installed",true);
  247.                 personasrotatorUrl='http://barisderin.com/?p=119';
  248.                 gBrowser.selectedTab = gBrowser.addTab(personasrotatorUrl);    
  249.  
  250.             }
  251.  
  252.             else {
  253.                 
  254.                 personasrotatorUrl='http://barisderin.com/?p=120';
  255.                 gBrowser.selectedTab = gBrowser.addTab(personasrotatorUrl);    
  256.  
  257.             }
  258.         
  259.         },
  260.         
  261.         aboutblanklistener:function  (event) {
  262.                 
  263.             if (event.originalTarget instanceof HTMLDocument) {
  264.                 
  265.                 var doc = event.originalTarget;
  266.  
  267.                 if (event.originalTarget.defaultView.frameElement) {
  268.                     
  269.                     while (doc.defaultView.frameElement) {
  270.                     
  271.                         doc=doc.defaultView.frameElement.ownerDocument;
  272.                         
  273.                     }
  274.                     
  275.                 } 
  276.             
  277.                 if (doc.defaultView.location.href.toString().search(PersonasRotator.openTabURI)!=-1) {
  278.                 
  279.                     doc.title=PersonasRotator.tabtitle;
  280.                                     
  281.                     if (PersonasRotator.imagespecified=="no") {
  282.  
  283.                         if (PersonasRotator.currentarrayindex<PersonasRotator.personasrotator.length) {
  284.                             
  285.                             PersonasRotator.currentimagefilename=PersonasRotator.personasrotator[PersonasRotator.currentarrayindex];
  286.                             PersonasRotator.currentarrayindex++;
  287.                             
  288.                         }
  289.                         
  290.                         else {
  291.                         
  292.                             PersonasRotator.currentarrayindex=0;
  293.                             PersonasRotator.currentimagefilename=PersonasRotator.personasrotator[PersonasRotator.currentarrayindex];
  294.                             PersonasRotator.currentarrayindex++;
  295.                             
  296.                         }
  297.                         
  298.                         PersonasRotatorFileIO.write(PersonasRotator.getChromeFile("config.abc"),PersonasRotator.currentarrayindex,'w',"UTF-8"); 
  299.                         
  300.                     }
  301.                 
  302.                     PersonasRotator.showThePersonaAtAboutBlank(doc,PersonasRotator.currentimagefilename);
  303.                 
  304.                     if (PersonasRotator.inpreview()) {
  305.                         
  306.                         var container = gBrowser.tabContainer;
  307.                     
  308.                         container.addEventListener("TabClose", PersonasRotator.exampleTabRemoved, false);
  309.  
  310.                     }
  311.                 
  312.                     if (PersonasRotator.currentarrayindex==PersonasRotator.personasrotator.length ) {
  313.                     
  314.                         PersonasRotator.newimage.src=PersonasRotator.assignFileURIToImage(PersonasRotator.personasrotator[0]);
  315.                         
  316.                     }
  317.  
  318.                     else {
  319.  
  320.                         PersonasRotator.newimage.src=PersonasRotator.assignFileURIToImage(PersonasRotator.personasrotator[PersonasRotator.currentarrayindex]);
  321.                         
  322.                     }
  323.                  
  324.                     if(PersonasRotator.currentimagefilename!=undefined){
  325.                         doc.addEventListener("mousedown",PersonasRotator.mouseclickondocument,false);
  326.                         doc.addEventListener("mouseup",PersonasRotator.mouseupondocument,false);
  327.                     }
  328.                     
  329.                     if (PersonasRotator.uploadrequested=='yes'){
  330.  
  331.                         PersonasRotator.uploadPersona(event,doc);
  332.  
  333.                     }
  334.  
  335.                     PersonasRotator.imagespecified="no"; 
  336.                     PersonasRotator.uploadrequested='no';
  337.                 
  338.                 }
  339.  
  340.                 if (doc.defaultView.location.href.toString().search("chrome://personasrotator/content/cc.html")!=-1) {
  341.     
  342.                     PersonasRotator.revertToPersonas();
  343.             
  344.                 }
  345.                 
  346.                 try {
  347.                     var domain=doc.domain;
  348.                 } catch (err) {
  349.                     return;
  350.                 }
  351.                 if (!domain) {
  352.                     return;
  353.                 }
  354.  
  355.                 if (domain.search(/personasrotator\.com$/) != -1) {
  356.                                     
  357.                     if (doc.defaultView.location.href.toString().search("http://personasrotator.com/persona/gallery/")!=-1) {
  358.                         
  359.                         if (doc.getElementById("extlogininfo")!=null) {
  360.                 
  361.                             if(!PersonasRotator.hasClass(doc.getElementById("extlogininfo"),"handled")) {
  362.                             
  363.                                 if(PersonasRotator.hasClass(doc.getElementById("extlogininfo"),"notlogged")) {
  364.                                 
  365.                                     doc.getElementById("extlogininfo").innerHTML='<a class="extinfoanchor" title="Please login to preview this persona" href="member.php">Please login to preview this persona</a>';
  366.                                     PersonasRotator.addClass(doc.getElementById("extlogininfo"),"handled");
  367.                                     
  368.                                 }
  369.                                 
  370.                             }
  371.                         
  372.                         }
  373.                                     
  374.                         if(doc.getElementById("extprebutdiv")!=null) {
  375.  
  376.                             if(doc.getElementById("extprebutton")==null) {
  377.                                 
  378.                                 doc.getElementById("extprebutdiv").innerHTML='<div style="background-color: rgb(139, 0, 0); width: 145px; height: 17px; cursor: pointer; padding-top: 3px; padding-bottom: 2px; background-repeat: no-repeat; background-image: url(http://personasrotator.com/media/images/indexpage/previewbutback.png);background-position: 52px 6px;" class="extinfoanchor" id="extprebutton" onclick="if(window.PersonasRotatorPreview){PersonasRotatorPreview.bringThePreviewDiv(event);} else{alert(\'Preview Module has not loaded yet. Please wait till the page is completely loaded.\')}" onmouseover="this.style.backgroundPosition=\'52px -21px\';" onmouseout="this.style.backgroundPosition=\'52px 6px\';"></div>';
  379.                                 PersonasRotator.addClass(doc.getElementById("extprebutdiv"),"extuser");
  380.                                 var scr=doc.createElement("script");
  381.                                 scr.setAttribute("src","http://personasrotator.com/inc/js/preview.js");
  382.                                 scr.setAttribute("type","text/javascript");
  383.                                 
  384.                                 doc.getElementsByTagName("head")[0].appendChild(scr);
  385.                                 
  386.                                 doc.addEventListener("personasrotatorSendToDesktopForPreview",PersonasRotator.sendToDesktopForPreview,false);
  387.                                 doc.addEventListener("personasrotatorPreviewInstall",PersonasRotator.previewInstallFromSite,false);
  388.                     
  389.                             }
  390.                             
  391.                         }
  392.                     
  393.                     }
  394.     
  395.                 }    
  396.                 
  397.             }
  398.             
  399.         },
  400.             
  401.         addClass:function(domnode, passedclass){
  402.         
  403.             if (!PersonasRotator.hasClass(domnode, passedclass)){
  404.                 
  405.                 if (domnode.className==""){domnode.className = passedclass;}
  406.                 else{domnode.className+=" "+passedclass;}
  407.                 
  408.             }
  409.         },    
  410.             
  411.         hasClass:function(domnode,passedclass){
  412.         
  413.             var searchpattern=new RegExp("( |^)"+passedclass+"($| )");
  414.             
  415.             if (searchpattern.test(domnode.className)) return true;
  416.             return false;
  417.             
  418.         },
  419.         
  420.         removeClass : function(domnode, passedclass){
  421.  
  422.             var searchpattern = new RegExp("( |^)"+passedclass+"($| )");
  423.             var classtring=domnode.className;
  424.             classtring=classtring.replace(searchpattern, "$1");
  425.             classtring=classtring.replace(/ $/, "");
  426.             domnode.className=classtring;
  427.  
  428.         },
  429.         
  430.         previewInstallFromSite:function(event){
  431.         
  432.             var doc;
  433.         
  434.             if (event.target.nodeName=="#document") {
  435.             
  436.                 doc=event.target;
  437.                 
  438.                 try {
  439.                     var domain=doc.domain;
  440.                 } catch (err) {
  441.                     return;
  442.                 }
  443.                 if (!domain) {
  444.                     return;
  445.                 }
  446.  
  447.                 if (domain.search(/personasrotator\.com$/) != -1) {
  448.                     
  449.                     if(doc.defaultView.location.href.toString().search(/personasrotator\.com\/persona\/gallery/) !=-1 ){
  450.                         
  451.                         openDialog('chrome://personasrotator/content/save.xul',"PersonasRotatorChoose"+Math.random(),"chrome,close=yes,centerscreen,modal",doc);
  452.                     
  453.                     }            
  454.                     
  455.                 }
  456.             
  457.             }
  458.  
  459.         },
  460.             
  461.         sendToDesktopForPreview:function(event){
  462.         
  463.             var doc;
  464.         
  465.             if (event.target.nodeName=="#document") {
  466.             
  467.                 doc=event.target;
  468.                 
  469.                 try {
  470.                     var domain=doc.domain;
  471.                 } catch (err) {
  472.                     return;
  473.                 }
  474.                 if (!domain) {
  475.                     return;
  476.                 }
  477.  
  478.                 if (domain.search(/personasrotator\.com$/) != -1) {
  479.                     
  480.                     if(doc.defaultView.location.href.toString().search(/personasrotator\.com\/persona\/gallery/) !=-1 ){
  481.                         
  482.                         var previewRequestObject={url:doc.defaultView.wrappedJSObject.PersonasRotatorPose.src,backgroundColor:doc.defaultView.wrappedJSObject.PersonasRotatorPose.backgroundColor,position:doc.defaultView.wrappedJSObject.PersonasRotatorPose.personasrotatorposition}
  483.                         
  484.                         PersonasRotator.previewThePersonaOnDesktop(previewRequestObject);
  485.                         
  486.                     }            
  487.                     
  488.                 }
  489.             
  490.             }
  491.  
  492.         },
  493.             
  494.         showThePersonaAtAboutBlank:function(doc,currentimagefilename) {
  495.             
  496.             var pos=PersonasRotator.assignPersonaPosition(currentimagefilename);
  497.             var backColor=PersonasRotator.assignPersonaBackgroundColor(currentimagefilename);
  498.             
  499.             doc.styleSheets[0].insertRule("body{background-position:"+(pos)+";background-repeat:no-repeat;background-image:"+PersonasRotator.assignPersonaImage(currentimagefilename)+";background-color:"+PersonasRotator.retrieveBackgroundColor(backColor)+";}",doc.styleSheets[0].cssRules.length);
  500.  
  501.             if(pos=="center center"){
  502.                 doc.defaultView.personaCenterNeed=true;
  503.                 doc.defaultView.imageSizeRetrieveCompleted=false;
  504.                 var image=new Image();
  505.                 image.src=PersonasRotator.assignFileURIToImage(PersonasRotator.retrievetabpersonaimage(doc));
  506.                 image.onload=function(event){
  507.                 
  508.                     doc.defaultView.personasrotatorImageWidth=image.width;
  509.                     doc.defaultView.personasrotatorImageHeight=image.height;
  510.                     doc.defaultView.imageSizeRetrieveCompleted=true;
  511.                     
  512.                 }    
  513.             
  514.             }
  515.             
  516.         },
  517.         
  518.         assignPersonaPosition:function(currentimagefilename) {
  519.         
  520.         return PersonasRotator.inpreview() ? "0px 0px" : (currentimagefilename==undefined ? "0px 0px" : PersonasRotator.retrievePersonaPositionForTheImage(currentimagefilename));
  521.  
  522.         },
  523.         
  524.         assignPersonaBackgroundColor:function(currentimagefilename) {
  525.         
  526.             return parseInt(PersonasRotator.retrievePersonaBackgroundColorForTheImage(PersonasRotator.currentimagefilename));
  527.             
  528.         },
  529.     
  530.         autoCenterPersona:function(paddingnode,imagewidth,imageheight){
  531.  
  532.             paddingnode.style.backgroundPosition=PersonasRotator.findHorizontalPositionOffset(null,imagewidth,paddingnode)+"px "+PersonasRotator.findVerticalPositionOffset(null,imageheight,paddingnode)+"px";
  533.     
  534.         },
  535.         
  536.         retrievePersonaPositionForTheImage:function(filename) {        
  537.             
  538.             if (filename==undefined || filename==null )    return;
  539.             
  540.             var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getTheURIFromFileName(PersonasRotator.createIndividualRDFFilename(filename)));
  541.             
  542.             var leafName=PersonasRotator.getTheLeafNameFromFileNameString(filename);
  543.  
  544.             var theImageNode = PersonasRotatorRDF.rdfService.GetResource(PersonasRotator.databaseResourceSiteName+PersonasRotator.createEncodedName(filename));
  545.             
  546.             var positionPredicate=PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#position");
  547.         
  548.             var positiontarget=ds.GetTarget(theImageNode,positionPredicate,true);
  549.             
  550.             if (positiontarget!=null) var position= positiontarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  551.             else return "0px 0px";
  552.         
  553.             return position;
  554.             
  555.         },    
  556.         
  557.         retrievePersonaBackgroundColorForTheImage:function(filename) {        
  558.             
  559.             if (filename==undefined || filename==null )    return;
  560.             
  561.             var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getTheURIFromFileName(PersonasRotator.createIndividualRDFFilename(filename)));
  562.             
  563.             var leafName=PersonasRotator.getTheLeafNameFromFileNameString(filename);
  564.  
  565.             var theImageNode = PersonasRotatorRDF.rdfService.GetResource(PersonasRotator.databaseResourceSiteName+PersonasRotator.createEncodedName(filename));
  566.             
  567.             var backgroundColorPredicate=PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#backgroundcolor");
  568.         
  569.             var backgroundColortarget=ds.GetTarget(theImageNode,backgroundColorPredicate,true);
  570.             
  571.             if (backgroundColortarget!=null) var backgroundColor= backgroundColortarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  572.             else return "0px 0px";
  573.         
  574.             return backgroundColor;
  575.             
  576.         },
  577.         
  578.         getTheURIFromFileName:function(filename) {
  579.         
  580.             if (filename==undefined || filename==null )    return;
  581.             
  582.             var namesplitarray=filename.split("/");
  583.             
  584.             var file = Components.classes["@mozilla.org/file/directory_service;1"]
  585.                                  .getService(Components.interfaces.nsIProperties)
  586.                                  .get("ProfD", Components.interfaces.nsIFile);
  587.  
  588.             file.append("personasrotator");
  589.                     
  590.             for (var i=0;i<namesplitarray.length;i++) {
  591.             
  592.                 file.append(namesplitarray[i]);
  593.             
  594.             }
  595.  
  596.             var ios = Components.classes["@mozilla.org/network/io-service;1"]
  597.                                 .getService(Components.interfaces.nsIIOService);
  598.             var URL = ios.newFileURI(file);
  599.  
  600.             return URL.spec;
  601.             
  602.         },
  603.  
  604.         createIndividualRDFFilename:function(filename) {
  605.             
  606.             if (filename==undefined || filename==null )    return;
  607.             
  608.             var array=filename.split(".");
  609.  
  610.             var imageextension=array[array.length-1];
  611.         
  612.             var rdffilename=filename+".rdf";
  613.             
  614.             var namesplitarray=rdffilename.split("/");
  615.         
  616.             var createdRDFName="";
  617.             
  618.             for (var i=0;i<namesplitarray.length;i++) {
  619.             
  620.                 if(i==namesplitarray.length-1) {createdRDFName+=namesplitarray[i];break;}
  621.                 if(i!=1) createdRDFName+=namesplitarray[i]+"/";
  622.                 else  createdRDFName+="RDFs/";
  623.                 
  624.             }
  625.  
  626.             return createdRDFName;
  627.             
  628.         },
  629.             
  630.         getTheLeafNameFromFileNameString:function(filename) {
  631.             
  632.             if (filename==undefined || filename==null )    return;
  633.             
  634.             var patharray=filename.split("/");
  635.             
  636.             var leafName=patharray[patharray.length-1];
  637.             
  638.             return leafName;
  639.  
  640.         },
  641.         
  642.         inpreview:function() {
  643.             
  644.             for (var i=0;i<PersonasRotator.previewtabs.length;i++) {
  645.             
  646.                 if (gBrowser.selectedTab==PersonasRotator.previewtabs[i]) return true;
  647.             
  648.             }
  649.             
  650.             return false;
  651.             
  652.         },
  653.         
  654.         assignPersonaImage:function(currentimagefilename) {
  655.         
  656.         return PersonasRotator.inpreview() ? 'url("'+PersonasRotator.previewurl +'")' : (currentimagefilename==undefined ? "none" : PersonasRotator.personasrotatorurlprefix+PersonasRotator.assignFileURIToImage(currentimagefilename)+PersonasRotator.personasrotatorurlsuffix);
  657.  
  658.         },
  659.         
  660.         exampleTabRemoved : function(event) {
  661.             
  662.             PersonasRotator.previewtabscopy=[];
  663.             
  664.                 for (var i=0;i<PersonasRotator.previewtabs.length;i++) {
  665.                 
  666.                     if (event.target==PersonasRotator.previewtabs[i]) {continue;}
  667.                     else {PersonasRotator.previewtabscopy.push(PersonasRotator.previewtabs[i])}
  668.                     
  669.                 }
  670.                 
  671.             if (PersonasRotator.previewtabs.length==1) PersonasRotator.previewtabs=[];
  672.             
  673.             else PersonasRotator.previewtabs=PersonasRotator.previewtabscopy;
  674.             
  675.             if(PersonasRotator.previewtabs.length==0) gBrowser.tabContainer.removeEventListener("TabClose", PersonasRotator.exampleTabRemoved, false);
  676.  
  677.         },
  678.  
  679.         mouseclickondocument:function  (event) {
  680.  
  681.             if (event.button==0 && PersonasRotator.CTRLpressed==true) {
  682.  
  683.                 if (this.defaultView.personaCenterNeed) {
  684.                 
  685.                     if(this.defaultView.imageSizeRetrieveCompleted){
  686.                         PersonasRotator.autoCenterPersona(this.body,this.defaultView.personasrotatorImageWidth,this.defaultView.personasrotatorImageHeight);
  687.                         this.defaultView.personaCenterNeed=false;
  688.                     }
  689.                     else {
  690.                         return;
  691.                     }
  692.                     
  693.                 }
  694.                     
  695.                 PersonasRotator.inmovemode=true;
  696.                 
  697.                 this.body.style.cursor="move";
  698.                 this.addEventListener("mousemove",PersonasRotator.documenttomousemoveo,false);
  699.                 this.addEventListener("mouseup",PersonasRotator.mouseupondocument,false);
  700.  
  701.                 PersonasRotator.moouseclickeventx=event.pageX;
  702.                 PersonasRotator.moouseclickeventy=event.pageY;
  703.  
  704.                 PersonasRotator.currentpersonapositionvalues=this.defaultView.getComputedStyle(this.body, null).getPropertyValue("background-position")
  705.                 PersonasRotator.currentpersonapositionxvalue=parseInt(PersonasRotator.currentpersonapositionvalues.split("px")[0]);
  706.                 PersonasRotator.currentpersonapositionyvalue=parseInt(PersonasRotator.currentpersonapositionvalues.split("px")[1]);
  707.                 event.stopPropagation();
  708.                 
  709.             }
  710.             
  711.         },
  712.         
  713.         documenttomousemoveo:function  (event) {
  714.         
  715.             if (PersonasRotator.inmovemode) {
  716.             
  717.             PersonasRotator.currenteventx=event.pageX;
  718.             PersonasRotator.currenteventy=event.pageY;
  719.  
  720.             PersonasRotator.moveonxpath=PersonasRotator.currenteventx-PersonasRotator.moouseclickeventx;
  721.             PersonasRotator.moveonypath=PersonasRotator.currenteventy-PersonasRotator.moouseclickeventy;
  722.  
  723.             placeonx=PersonasRotator.currentpersonapositionxvalue+PersonasRotator.moveonxpath;
  724.             placeony=PersonasRotator.currentpersonapositionyvalue+PersonasRotator.moveonypath;
  725.             
  726.             this.body.style.backgroundPosition=placeonx+"px "+placeony+"px";
  727.             this.body.style.personaRepeat="no-repeat";
  728.             
  729.             }
  730.             
  731.             event.stopPropagation();
  732.  
  733.         },
  734.  
  735.         mouseupondocument:function  (event) {
  736.         
  737.             if (event.button==0) {
  738.             
  739.                 PersonasRotator.inmovemode=false;
  740.                 
  741.                 this.body.style.cursor="default";
  742.                 this.removeEventListener("mousemove",PersonasRotator.documenttomousemoveo,false);
  743.                 this.removeEventListener("mouseup",PersonasRotator.mouseupondocument,false);
  744.                 
  745.                 if (PersonasRotator.inpreview()) return;
  746.                 PersonasRotator.currentpersonapositionvalues="";
  747.                 PersonasRotator.currentpersonapositionxvalue=0;
  748.                 PersonasRotator.currentpersonapositionyvalue=0;
  749.                 PersonasRotator.currenteventx=0;
  750.                 PersonasRotator.currenteventy=0;
  751.                 PersonasRotator.moveonxpath=0;
  752.                 PersonasRotator.moveonypath=0;
  753.                 
  754.                 this.styleSheets[0].insertRule("body{background-position:"+this.defaultView.getComputedStyle(this.body, null).getPropertyValue("background-position")+";}",this.styleSheets[0].cssRules.length);
  755.                 
  756.                 this.body.removeAttribute("style");
  757.                 
  758.                 PersonasRotator.savePersonaPositionGlobally(PersonasRotator.retrievetabpersonaimage(this),this);
  759.  
  760.                 event.stopPropagation();
  761.                 
  762.             }
  763.             
  764.         },
  765.             
  766.         CTRLupondocument:function  (doc) {        
  767.             
  768.                 doc.body.style.cursor="default";
  769.                 doc.removeEventListener("mousemove",PersonasRotator.documenttomousemoveo,false);
  770.                 doc.removeEventListener("mouseup",PersonasRotator.mouseupondocument,false);
  771.                 
  772.                 if (PersonasRotator.inpreview()) return;
  773.                 PersonasRotator.currentpersonapositionvalues="";
  774.                 PersonasRotator.currentpersonapositionxvalue=0;
  775.                 PersonasRotator.currentpersonapositionyvalue=0;
  776.                 PersonasRotator.currenteventx=0;
  777.                 PersonasRotator.currenteventy=0;
  778.                 PersonasRotator.moveonxpath=0;
  779.                 PersonasRotator.moveonypath=0;
  780.                 
  781.                 doc.styleSheets[0].insertRule("body{background-position:"+doc.defaultView.getComputedStyle(doc.body, null).getPropertyValue("background-position")+";}",doc.styleSheets[0].cssRules.length);
  782.                 
  783.                 doc.body.removeAttribute("style");
  784.                 
  785.                 PersonasRotator.savePersonaPositionGlobally(PersonasRotator.retrievetabpersonaimage(doc),doc);
  786.  
  787.             
  788.         },
  789.  
  790.         savePersonaPositionGlobally:function(filename,doc) {
  791.         
  792.             if (filename==undefined) return;
  793.             PersonasRotator.savePersonaPositionForTheImage(filename,doc);
  794.             PersonasRotator.updatePersonaPositionForTheImageOnLibraryRdf(filename,doc);
  795.             PersonasRotator.updatePersonaPositionForTheImageOnCollectionRdf(filename,doc);
  796.  
  797.         },
  798.         
  799.         retrievetabpersonaimage:function (doc) {
  800.     
  801.             if (doc.defaultView.personasrotatorconfigobject != undefined ) {
  802.             
  803.                 return doc.defaultView.personasrotatorconfigobject.compositefilename;
  804.                 
  805.             }
  806.             
  807.             var personaImageComputedCssValue=doc.defaultView.getComputedStyle(doc.body, null).getPropertyValue("background-image");
  808.             
  809.             if(personaImageComputedCssValue!="none"){
  810.             
  811.                 var tabpersonaimagenamesplitarray=personaImageComputedCssValue.split(/url\(\s*["']?([^"']+)["']?\s*\)/)[1].split(PersonasRotator.personaImagePreName)[1].replace(/\\/g,"");
  812.             
  813.             }
  814.             
  815.             else {
  816.  
  817.                 return undefined;
  818.                 
  819.             }
  820.         
  821.             return PersonasRotator.createDecodedNameFromFileURI(tabpersonaimagenamesplitarray);
  822.  
  823.         },
  824.         
  825.         savePersonaPositionForTheImage:function(filename,doc) {
  826.             
  827.             var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getTheURIFromFileName(PersonasRotator.createIndividualRDFFilename(filename)));
  828.             
  829.             var leafName=PersonasRotator.getTheLeafNameFromFileNameString(filename);
  830.  
  831.             var theImageNode = PersonasRotatorRDF.rdfService.GetResource(PersonasRotator.databaseResourceSiteName+PersonasRotator.createEncodedName(filename));
  832.             
  833.             var positionPredicate=PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#position");
  834.         
  835.             var positiontarget=ds.GetTarget(theImageNode,positionPredicate,true);
  836.             
  837.             if (positiontarget!=null) var position= positiontarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  838.             else {return}
  839.             
  840.             var newposition;
  841.             
  842.             if(doc.defaultView.location.href.toString().search(/personasrotator\.com\/persona\/gallery/) ==-1 ){
  843.                 newposition=doc.defaultView.getComputedStyle(doc.body, null).getPropertyValue("background-position");
  844.             }
  845.             
  846.             else {
  847.                 newposition=doc.defaultView.wrappedJSObject.PersonasRotatorPose.personasrotatorposition;    
  848.             }
  849.             var predicate=PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#position");
  850.             var oldtarget=PersonasRotatorRDF.rdfService.GetLiteral(position);
  851.             var newtarget=PersonasRotatorRDF.rdfService.GetLiteral(newposition);
  852.             
  853.             ds.Change(theImageNode,predicate,oldtarget,newtarget);
  854.             
  855.             try{
  856.             ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  857.             }
  858.             catch(err){
  859.             
  860.             }
  861.         
  862.         },    
  863.         
  864.         updatePersonaPositionForTheImageOnLibraryRdf:function(filename,doc) {
  865.             
  866.             var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getlibraryfileURI());
  867.             
  868.             var leafName=PersonasRotator.getTheLeafNameFromFileNameString(filename);
  869.  
  870.             var theImageNode = PersonasRotatorRDF.rdfService.GetResource(PersonasRotator.databaseResourceSiteName+PersonasRotator.createEncodedName(filename));
  871.             
  872.             var positionPredicate=PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#position");
  873.         
  874.             var positiontarget=ds.GetTarget(theImageNode,positionPredicate,true);
  875.             
  876.             if (positiontarget!=null) var position= positiontarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  877.             else {return}
  878.             
  879.             var newposition=doc.defaultView.getComputedStyle(doc.body, null).getPropertyValue("background-position");
  880.             
  881.             var predicate=PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#position");
  882.             var oldtarget=PersonasRotatorRDF.rdfService.GetLiteral(position);
  883.             var newtarget=PersonasRotatorRDF.rdfService.GetLiteral(newposition);
  884.             
  885.             ds.Change(theImageNode,predicate,oldtarget,newtarget);
  886.             
  887.             try{
  888.             ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();                    
  889.             }
  890.             catch(err){
  891.             
  892.             }
  893.         },
  894.         
  895.         updatePersonaPositionForTheImageOnCollectionRdf:function(filename,doc) {
  896.             
  897.             var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getTheURIFromFileName(PersonasRotator.createCollectionRDfFileName(filename)));
  898.             
  899.             var leafName=PersonasRotator.getTheLeafNameFromFileNameString(filename);
  900.  
  901.             var theImageNode = PersonasRotatorRDF.rdfService.GetResource(PersonasRotator.databaseResourceSiteName+PersonasRotator.createEncodedName(filename));
  902.             
  903.             var positionPredicate=PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#position");
  904.         
  905.             var positiontarget=ds.GetTarget(theImageNode,positionPredicate,true);
  906.             
  907.             if (positiontarget!=null) var position= positiontarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  908.             else {return}
  909.             
  910.             var newposition=doc.defaultView.getComputedStyle(doc.body, null).getPropertyValue("background-position");
  911.             
  912.             var predicate=PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#position");
  913.             var oldtarget=PersonasRotatorRDF.rdfService.GetLiteral(position);
  914.             var newtarget=PersonasRotatorRDF.rdfService.GetLiteral(newposition);
  915.             
  916.             ds.Change(theImageNode,predicate,oldtarget,newtarget);
  917.             
  918.             try{            
  919.             ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();                
  920.             }
  921.             catch(err){
  922.             
  923.             }
  924.         },
  925.  
  926.         CTRLKeydownListener:function(event){
  927.         
  928.             if (event.which==17) {
  929.  
  930.                 PersonasRotator.CTRLpressed=true;
  931.                 
  932.                 if (window.content.location.href.toString().search("http://personasrotator.com/persona/gallery/")!=-1) {
  933.                     
  934.                     if(window.content.document.getElementById("pre_info")!=null) {
  935.                     
  936.                         var changeCTRLpressedEvent = window.content.document.createEvent("Events"); 
  937.                         changeCTRLpressedEvent.initEvent("CTRLKeydownpressed", false, false, window.content, null); 
  938.                         window.content.document.dispatchEvent(changeCTRLpressedEvent);
  939.                         
  940.                     }
  941.                 
  942.                 }                
  943.                             
  944.             }
  945.         
  946.         },
  947.  
  948.         CTRLKeyupListener:function(event){
  949.         
  950.             if (event.which==17) {
  951.             
  952.                 PersonasRotator.CTRLpressed=false;
  953.                 
  954.                 if (window.content.location.href.toString().search(PersonasRotator.openTabURI)!=-1) {
  955.                     
  956.                     if(PersonasRotator.inmovemode==true) {PersonasRotator.inmovemode=false;PersonasRotator.CTRLupondocument(window.content.document);}
  957.                     
  958.                 }            
  959.         
  960.                 if (window.content.location.href.toString().search("http://personasrotator.com/persona/gallery/")!=-1) {
  961.                     
  962.                     if(window.content.document.getElementById("pre_info")!=null) {
  963.                     
  964.                         var changeCTRLpressedEvent = window.content.document.createEvent("Events"); 
  965.                         changeCTRLpressedEvent.initEvent("CTRLKeyuppressed", false, false, window.content, null); 
  966.                         window.content.document.dispatchEvent(changeCTRLpressedEvent);
  967.                         
  968.                     }
  969.                 
  970.                 }    
  971.                 
  972.             }
  973.         
  974.         },
  975.                     
  976.         handlepop:function(event){
  977.             
  978.             if (document.popupNode.ownerDocument.location.href==PersonasRotator.openTabURI && !PersonasRotator.inpreview()) {
  979.                                 
  980.                 var shownormalcontextcheckbox=document.getElementById("shownormalcontextcheckbox");
  981.                 
  982.                 var personasrotatorprefsinstance = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  983.  
  984.                 var showpersonasrotatortabnormalcontext = personasrotatorprefsinstance.getBoolPref("extensions.personasrotator.showpersonasrotatortabnormalcontext");
  985.                         
  986.                 if(showpersonasrotatortabnormalcontext){
  987.                     
  988.                     document.getElementById("personasrotator-normalcontext-uploadpersona").setAttribute("hidden","false");
  989.                     
  990.                     document.getElementById("personasrotator-normalcontext-visitpersonapage").setAttribute("hidden","false");
  991.  
  992.                 }
  993.  
  994.                 else{
  995.                 
  996.                     if(!PersonasRotator.hasClass(document.popupNode.ownerDocument.body,"uploadformshowing")){
  997.                         
  998.                         event.preventDefault();
  999.                         
  1000.                         document.getElementById("PersonasRotatorTabContextMenu").openPopupAtScreen( event.screenX, event.screenY,false );
  1001.                                             
  1002.                     }
  1003.                     
  1004.                     else {
  1005.                         
  1006.                         var rightClickNode=document.popupNode;
  1007.                         
  1008.                         var normalContextShowable=false;
  1009.                         
  1010.                         while(rightClickNode!=null){
  1011.                         
  1012.                             if(rightClickNode==document.popupNode.ownerDocument.getElementById("personasrotatoruploadform")){
  1013.                             
  1014.                                 normalContextShowable=true;
  1015.                             
  1016.                             }
  1017.                             
  1018.                             rightClickNode=rightClickNode.parentNode;
  1019.                         
  1020.                         }
  1021.                         
  1022.                         if(!normalContextShowable){
  1023.                                                 
  1024.                             event.preventDefault();
  1025.                             
  1026.                             document.getElementById("PersonasRotatorTabContextMenu").openPopupAtScreen( event.screenX, event.screenY,false );
  1027.                                                 
  1028.                         }
  1029.                         
  1030.                         else{
  1031.                             
  1032.                             document.getElementById("personasrotator-normalcontext-uploadpersona").setAttribute("hidden","true");
  1033.  
  1034.                             document.getElementById("personasrotator-normalcontext-visitpersonapage").setAttribute("hidden","true");
  1035.                         
  1036.                         }
  1037.                     
  1038.                     }
  1039.  
  1040.                 }                
  1041.                                         
  1042.             }
  1043.  
  1044.             else {
  1045.                 
  1046.                 document.getElementById("personasrotator-normalcontext-uploadpersona").setAttribute("hidden","true");
  1047.  
  1048.                 document.getElementById("personasrotator-normalcontext-visitpersonapage").setAttribute("hidden","true");
  1049.  
  1050.             }
  1051.             
  1052.         },        
  1053.                     
  1054.         handleTabContextMenuPopup: function (event) {
  1055.             
  1056.         },        
  1057.         
  1058.         revertToPersonas:function(){
  1059.  
  1060.             PersonasRotator.bringPersonas();
  1061.     
  1062.         },        
  1063.     
  1064.         handlePreviewCommand:function(event){
  1065.  
  1066.             PersonasRotator.previewurl=gContextMenu.imageURL;
  1067.             PersonasRotator.imagespecified='yes';
  1068.             var k = gBrowser.addTab(PersonasRotator.openTabURI);
  1069.             gBrowser.selectedTab=k;
  1070.             PersonasRotator.previewtabs.push(k);
  1071.  
  1072.         },
  1073.         
  1074.         populateItems : function () {
  1075.         
  1076.             var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getlibraryfileURI());    
  1077.  
  1078.             var container=PersonasRotatorRDF.rdfContainerUtils.MakeSeq(ds,PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator:library"));
  1079.             var genericpersonasseqenumurator=container.GetElements();
  1080.             var namePredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#name");
  1081.  
  1082.             while (genericpersonasseqenumurator.hasMoreElements()) {
  1083.         
  1084.                 var collection=genericpersonasseqenumurator.getNext();
  1085.                 
  1086.                 var nametarget=ds.GetTarget(collection,namePredicate,true);
  1087.                 
  1088.                 if (nametarget) {
  1089.                     
  1090.                     var name = nametarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  1091.  
  1092.                 }
  1093.  
  1094.                 var newmenuitem=document.createElement("menuitem");
  1095.  
  1096.                 newmenuitem.setAttribute("label",name);
  1097.                 
  1098.                 newmenuitem.setAttribute("id",name+"menuitem");
  1099.                 
  1100.                 newmenuitem.setAttribute("oncommand","PersonasRotator.savepreview(event.target.getAttribute('label'),PersonasRotator.retrievetabpersonaimageforhttp(document.popupNode.ownerDocument),document.popupNode.ownerDocument);");
  1101.             
  1102.                 newmenuitem.setAttribute("class","collection-menuitem");
  1103.                 
  1104.                 document.getElementById("abc-savepreview-menu-popup").appendChild(newmenuitem);
  1105.         
  1106.             }
  1107.  
  1108.         },
  1109.         
  1110.         retrievetabpersonaimageforhttp:function (doc) {
  1111.             
  1112.             return doc.defaultView.getComputedStyle(doc.body, null).getPropertyValue("background-image").split(/url\(\s*["']?([^"']+)["']?\s*\)/)[1].replace(/\\/g,"");
  1113.  
  1114.         },    
  1115.         
  1116.         retrievetabpersonaimagefrompersonasrotator:function (doc) {
  1117.             
  1118.             return doc.defaultView.getComputedStyle(doc.getElementById("pre_main"), null).getPropertyValue("background-image").split(/url\(\s*["']?([^"']+)["']?\s*\)/)[1].replace(/\\/g,"");
  1119.  
  1120.         },
  1121.         
  1122.         clearItems:function (event){
  1123.         
  1124.             var menupopupnode=event.target;
  1125.         
  1126.             var length=menupopupnode.childNodes.length;
  1127.  
  1128.             for (var f=length - 1; 0<=f;f--) {
  1129.                 
  1130.                     menupopupnode.removeChild(menupopupnode.childNodes[f]);
  1131.  
  1132.             }
  1133.  
  1134.         },    
  1135.  
  1136.         savepreview:function(chosencolname,url,doc) {
  1137.             
  1138.             var source = PersonasRotator.createNewURIfromHttpURL(url);
  1139.         
  1140.             var filem=PersonasRotator.getTheFileThePreviewImageWillBeSaved(chosencolname,source,url,doc);
  1141.             
  1142.             PersonasRotator.downloadAndSaveThePrevieImage(chosencolname,source,filem,doc);
  1143.  
  1144.         },
  1145.          
  1146.         createNewURIfromHttpURL:function(url) {
  1147.             
  1148.             var io = Components.classes["@mozilla.org/network/io-service;1"]
  1149.                          .getService(Components.interfaces.nsIIOService);
  1150.  
  1151.             return io.newURI(url, "UTF8", null);
  1152.  
  1153.         },
  1154.         
  1155.         getTheFileThePreviewImageWillBeSaved: function(chosencolname,source,url,doc) {
  1156.  
  1157.             var patharray=  source.path.split("/");
  1158.             
  1159.             var leafName=PersonasRotator.createDecodedNameFromFileURI(patharray[patharray.length-1]);
  1160.             
  1161.             var createdCompositeFileName=chosencolname+"/"+"Personas"+"/"+leafName;
  1162.  
  1163.             var filename=PersonasRotator.checkNameCollison(createdCompositeFileName);
  1164.             
  1165.             doc.defaultView.personasrotatorpreviewfilename=filename;
  1166.             
  1167.             return PersonasRotator.getChromeFile(filename);
  1168.             
  1169.         },
  1170.             
  1171.         checkNameCollison: function (filename) {
  1172.         
  1173.             var file =PersonasRotator.getChromeFile(filename);
  1174.             
  1175.             var inc=1;
  1176.             
  1177.             var changedname="";
  1178.             
  1179.             while (file.exists()) {
  1180.                         
  1181.             inc++;
  1182.                 
  1183.             var namesplitarray=filename.split("/");
  1184.  
  1185.             for (var i=0;i<namesplitarray.length;i++) {
  1186.             
  1187.                 if(i==namesplitarray.length-1) {
  1188.  
  1189.                     var array=namesplitarray[i].split(".");
  1190.  
  1191.                     var imageextension=array[array.length-1];
  1192.  
  1193.                     var newLeafName=namesplitarray[i].replace("."+imageextension,"("+inc+")"+"."+imageextension);
  1194.                 
  1195.                     changedname+=newLeafName;
  1196.                     
  1197.                     break;
  1198.  
  1199.                 }
  1200.                 
  1201.                 changedname+=namesplitarray[i]+"/";
  1202.  
  1203.             }
  1204.             
  1205.                 filename=changedname;
  1206.                 
  1207.                 file =PersonasRotator.getChromeFile(filename);
  1208.                 
  1209.                 changedname="";
  1210.                 
  1211.             }
  1212.         
  1213.             return filename;
  1214.  
  1215.         },
  1216.         
  1217.         downloadAndSaveThePrevieImage: function (chosencolname,source,filem,doc) {
  1218.             
  1219.             var persist=Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist);
  1220.  
  1221.             persist.persistFlags=Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
  1222.             
  1223.             persist.persistFlags |=Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
  1224.       
  1225.             persist.progressListener={
  1226.  
  1227.                 onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {
  1228.  
  1229.                 },
  1230.                 
  1231.                 onStateChange: function(aWebProgress, aRequest, aFlag, aStatus) {
  1232.                    
  1233.                     if(aFlag==327696){
  1234.                     
  1235.                         PersonasRotator.prepareForPreviewImageThumbSave(chosencolname,doc.defaultView.personasrotatorpreviewfilename,doc);
  1236.                     
  1237.                     }
  1238.                 
  1239.                 },
  1240.                 
  1241.             }
  1242.  
  1243.             persist.saveURI(source, null, null, null, null, filem);
  1244.  
  1245.         },
  1246.         
  1247.         createTheThumbandSave:function(ctx,img,canvas,filey,doc,chosencolname){
  1248.         
  1249.             ctx.clearRect(0,0,138,109);
  1250.                                 
  1251.             var array=img.src.split(".");
  1252.  
  1253.             var imageextension=array[array.length-1];
  1254.             
  1255.             if(imageextension!="png" && imageextension!="gif") {
  1256.                 
  1257.                 ctx.fillStyle="#f5f5f5";
  1258.                 ctx.fillRect(0, 0, 138, 109);
  1259.                 
  1260.             }
  1261.             
  1262.             var imagewidth=img.naturalWidth;
  1263.             var imageheight=img.naturalHeight;
  1264.             var widthratio=imagewidth/138.0;
  1265.             var heightratio=imageheight/109.0;
  1266.             
  1267.             var correctratio=(widthratio>heightratio) ? widthratio :heightratio;
  1268.             
  1269.             var heightforresize=imageheight/correctratio;
  1270.             var widthforresize=imagewidth/correctratio;
  1271.             
  1272.             var verticalposition=(109-heightforresize)/2;
  1273.             var horiziontalposition=(138-widthforresize)/2;
  1274.             
  1275.             ctx.drawImage(img,horiziontalposition,verticalposition,widthforresize,heightforresize);
  1276.             PersonasRotator.saveCanvas(canvas,filey.path,chosencolname,doc);
  1277.         
  1278.         },
  1279.         
  1280.         prepareForPreviewImageThumbSave:function (chosencolname,filename,doc) {
  1281.                 
  1282.             var inc=0;
  1283.             
  1284.             var filey = PersonasRotator.getThumbFile(filename);
  1285.         
  1286.             var img = new Image();
  1287.             
  1288.             var canvas=document.getElementById("PersonasRotatorMainCanvas");
  1289.  
  1290.             var ctx = canvas.getContext('2d');
  1291.  
  1292.             img.onload = function() {
  1293.             
  1294.                 window.setTimeout(function(){
  1295.                             
  1296.                         try{
  1297.  
  1298.                             PersonasRotator.createTheThumbandSave(ctx,img,canvas,filey,doc,chosencolname);
  1299.                     
  1300.                         }
  1301.                         
  1302.                         catch(err){
  1303.  
  1304.                             looper(inc);
  1305.  
  1306.                         }
  1307.                             
  1308.                 },1);
  1309.                 
  1310.             }
  1311.  
  1312.             var fileyx =PersonasRotator.getChromeFile(filename);
  1313.               
  1314.             var iox = Components.classes["@mozilla.org/network/io-service;1"]
  1315.                          .getService(Components.interfaces.nsIIOService);
  1316.                      
  1317.             var targetx = iox.newFileURI(fileyx);
  1318.             
  1319.             function looper(inc) {
  1320.             
  1321.                 window.setTimeout(function(){
  1322.                             
  1323.                     try{
  1324.                     
  1325.                         PersonasRotator.createTheThumbandSave(ctx,img,canvas,filey,doc,chosencolname);
  1326.                     
  1327.                     }
  1328.                     
  1329.                     catch(err){
  1330.  
  1331.                         looper(inc++);
  1332.  
  1333.                     }
  1334.             
  1335.                 },(inc+1)*50);    
  1336.             
  1337.             }
  1338.             
  1339.             img.setAttribute("src",targetx.spec);
  1340.  
  1341.         },
  1342.                 
  1343.         getThumbFile:function(filename) {
  1344.             
  1345.             var createdThumbImageName=PersonasRotator.createThumbImageName(filename);
  1346.         
  1347.             return PersonasRotator.getChromeFile(createdThumbImageName);
  1348.  
  1349.         },
  1350.  
  1351.         createThumbImageName:function(filename){
  1352.         
  1353.             var namesplitarray=filename.split("/");
  1354.         
  1355.             var createdThumbImageName="";
  1356.             
  1357.             for (var i=0;i<namesplitarray.length;i++) {
  1358.             
  1359.                 if(i==namesplitarray.length-1) {createdThumbImageName+="Thumb_"+namesplitarray[i];break;}
  1360.                 if(i!=1) createdThumbImageName+=namesplitarray[i]+"/";
  1361.                 else  createdThumbImageName+="Thumbs/";
  1362.                 
  1363.             }
  1364.  
  1365.             return createdThumbImageName;
  1366.             
  1367.         },
  1368.         
  1369.         saveCanvas:function (canvas, destFile,chosencolname,doc) {
  1370.           
  1371.           var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  1372.           file.initWithPath(destFile);
  1373.           
  1374.           var io = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  1375.              
  1376.           var source = io.newURI(canvas.toDataURL(PersonasRotator.createMIMEType(destFile) , ""), "UTF8", null);
  1377.           var target = io.newFileURI(file)
  1378.           
  1379.           var persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist);
  1380.           
  1381.           persist.persistFlags = Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
  1382.           persist.persistFlags |= Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
  1383.  
  1384.             persist.progressListener = {
  1385.  
  1386.                 onStateChange: function(aWebProgress, aRequest, aFlag, aStatus){
  1387.                     
  1388.                     if(aFlag==327696){
  1389.                         
  1390.                         PersonasRotator.createOtherImageRequirements(chosencolname,doc.defaultView.personasrotatorpreviewfilename,doc)
  1391.  
  1392.                     }
  1393.  
  1394.                 }
  1395.  
  1396.             }
  1397.           
  1398.           persist.saveURI(source, null, null, null, null, file);
  1399.           
  1400.         },
  1401.         
  1402.         createMIMEType:function(destFile){
  1403.         
  1404.             if(destFile.search(/\.png$/i)!=-1) return "image/png";
  1405.             if(destFile.search(/\.jpg$/i)!=-1 || destFile.search(/\.jpeg$/i)!=-1) return "image/jpeg";
  1406.             if(destFile.search(/\.svg$/i)!=-1) return "image/svg+xml";
  1407.             return "image/png";
  1408.         
  1409.         },    
  1410.         
  1411.         createOtherImageRequirements:function (chosencolname,filename,doc) {
  1412.             
  1413.             PersonasRotator.createEmptyRdf(filename,doc);
  1414.             
  1415.             PersonasRotator.savePersonaPositionForTheImage(filename,doc);
  1416.             
  1417.             PersonasRotator.addImageResourceNodeToLibraryDatabase(chosencolname,filename,doc);
  1418.             
  1419.             PersonasRotator.addImageResourceNodeToCollectionDatabase(chosencolname,filename,doc);
  1420.             
  1421.             PersonasRotator.tryToPopulatePersonaWindow(chosencolname,filename);
  1422.         
  1423.             PersonasRotator.personaimagesarraymaker();
  1424.     
  1425.             //var imagelocation=filename;
  1426.             //PersonasRotator.currentimagefilename=imagelocation;
  1427.             //PersonasRotator.imagespecified='yes';
  1428.             //PersonasRotator.newimage.src=PersonasRotator.assignFileURIToImage(imagelocation);
  1429.             
  1430.             PersonasRotator.refreshPreviewTabsArray();
  1431.             
  1432.             doc.defaultView.personasrotatorpreviewfilename=null;
  1433.             
  1434.             var personasrotatorconfigobject=new Object();
  1435.             
  1436.             personasrotatorconfigobject.compositefilename=filename;
  1437.             
  1438.             doc.defaultView.personasrotatorconfigobject=personasrotatorconfigobject;
  1439.         
  1440.             if(doc.defaultView.location.href.toString().search(/personasrotator\.com\/persona\/gallery/) !=-1 ){
  1441.                     
  1442.                 var PersonasRotatorInstalledEvent = doc.createEvent("Events"); 
  1443.                 PersonasRotatorInstalledEvent.initEvent("PersonasRotatorInstalled", false, false, doc.defaultView, null); 
  1444.                 doc.dispatchEvent(PersonasRotatorInstalledEvent);                    
  1445.                 
  1446.             }
  1447.         
  1448.             //PersonasRotator.createAlertPrompt("Persona installed successfully! Open a new tab to view it.");
  1449.                     
  1450.         },
  1451.  
  1452.         retrieveDesktopBackgroundColor:function(){
  1453.  
  1454.             return Components.classes["@mozilla.org/browser/shell-service;1"].getService(Components.interfaces.nsIShellService).desktopBackgroundColor;
  1455.                                                  
  1456.         },
  1457.         
  1458.         createEmptyRdf:function(filename,doc){
  1459.             
  1460.             var descriptionForImage,nameForImage,locationForImage,positionForImage,defaultForImage,activecollectioname,version,uploaded,siteURI,source,screenRes,tagsForImage,versionForImage,uploadedForImage,siteURIForImage,sourceForImage,screenResForImage,backgroundColorForImage;    
  1461.                 
  1462.             var preSource="";
  1463.             
  1464.             var collename=filename.split("/")[0];
  1465.             
  1466.             if(doc.defaultView.location.href.toString().search(/personasrotator\.com\/persona\/gallery/) !=-1 ){
  1467.                 
  1468.                 preSource="site";
  1469.                 
  1470.             }
  1471.             
  1472.             if(preSource=="site"){
  1473.                 
  1474.                 nameForImage=doc.getElementsByClassName("nameForImage")[0].firstChild.nodeValue.replace(/&/g,"&");
  1475.                 locationForImage=PersonasRotator.getTheLeafNameFromFileNameString(filename).replace(/&/g,"&");
  1476.                 descriptionForImage=doc.getElementsByClassName("personadescription")[0].textContent.replace(/&/g,"&").replace(/"/g,'\\"');
  1477.                 positionForImage="0px 0px";
  1478.                 defaultForImage="false";
  1479.                 tagsForImage=collename.replace(/&/g,"&")+","+PersonasRotator.retrieveTagsFromSite(doc,collename).replace(/&/g,"&");
  1480.                 versionForImage="0.1";
  1481.                 uploadedForImage="true";
  1482.                 siteURIForImage=doc.defaultView.location.href.toString().replace(/&/g,"&");
  1483.                 sourceForImage="site";
  1484.                 screenResForImage=doc.getElementById("pre_main_screenRes").className;
  1485.                 backgroundColorForImage=doc.getElementById("pre_main_backgroundColor").className;
  1486.                 
  1487.             }
  1488.             
  1489.             else {
  1490.                 
  1491.                 nameForImage=PersonasRotator.getTheLeafNameFromFileNameString(filename).replace(/\.\w+$/,"").replace(/&/g,"&");
  1492.                 locationForImage=PersonasRotator.getTheLeafNameFromFileNameString(filename).replace(/&/g,"&");
  1493.                 descriptionForImage="undefined";
  1494.                 positionForImage="0px 0px";
  1495.                 defaultForImage="false";
  1496.                 tagsForImage=filename.split("/")[0].replace(/&/g,"&");
  1497.                 versionForImage="0.1";
  1498.                 uploadedForImage="false";
  1499.                 siteURIForImage="null".replace(/&/g,"&");
  1500.                 sourceForImage="external";
  1501.                 screenResForImage=screen.width+"x"+screen.height;        
  1502.                 backgroundColorForImage=PersonasRotator.retrieveDesktopBackgroundColor();        
  1503.                 
  1504.             }
  1505.         
  1506.             var RDFstring='<?xml version="1.0"?>'+'<RDF:RDF xmlns:personasrotator="urn:personasrotator#" xmlns:NC="http://home.netscape.com/NC-rdf#" xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'+
  1507.             
  1508.             '<RDF:Description  RDF:about="'+(PersonasRotator.databaseResourceSiteName+PersonasRotator.createEncodedName(filename)).replace(/&/g,"&")+'">'+
  1509.             
  1510.             '<personasrotator:name>'+nameForImage.replace(/>/g,">").replace(/</g,"<")+'</personasrotator:name>'+
  1511.             '<personasrotator:location>'+locationForImage.replace(/>/g,">").replace(/</g,"<")+'</personasrotator:location>'+
  1512.             '<personasrotator:description>'+descriptionForImage.replace(/>/g,">").replace(/</g,"<")+'</personasrotator:description>'+
  1513.             '<personasrotator:position>'+positionForImage.replace(/>/g,">").replace(/</g,"<")+'</personasrotator:position>'+
  1514.             '<personasrotator:default>'+defaultForImage.replace(/>/g,">").replace(/</g,"<")+'</personasrotator:default>'+
  1515.             '<personasrotator:tags>'+tagsForImage.replace(/>/g,">").replace(/</g,"<")+'</personasrotator:tags>'+
  1516.             '<personasrotator:version>'+versionForImage.replace(/>/g,">").replace(/</g,"<")+'</personasrotator:version>'+
  1517.             '<personasrotator:uploaded>'+uploadedForImage.replace(/>/g,">").replace(/</g,"<")+'</personasrotator:uploaded>'+
  1518.             '<personasrotator:siteuri>'+siteURIForImage.replace(/>/g,">").replace(/</g,"<")+'</personasrotator:siteuri>'+
  1519.             '<personasrotator:source>'+sourceForImage.replace(/>/g,">").replace(/</g,"<")+'</personasrotator:source>'+
  1520.             '<personasrotator:screenres>'+screenResForImage.replace(/>/g,">").replace(/</g,"<")+'</personasrotator:screenres>'+
  1521.             '<personasrotator:backgroundcolor>'+backgroundColorForImage.replace(/>/g,">").replace(/</g,"<")+'</personasrotator:backgroundcolor>'+
  1522.             
  1523.             '</RDF:Description></RDF:RDF>';
  1524.             
  1525.             var emptyRDFnsiFile=PersonasRotator.getChromeFile(PersonasRotator.createIndividualRDFFilename(filename));
  1526.             
  1527.             PersonasRotatorFileIO.write(emptyRDFnsiFile,RDFstring,"w","UTF-8");
  1528.         
  1529.         },
  1530.             
  1531.         retrieveTagsFromSite:function (doc,collename) {
  1532.             
  1533.             var tagsArray=doc.getElementsByClassName("personasrotatortags");
  1534.             
  1535.             var textLiteral="";
  1536.             
  1537.             for (var i=0;i<tagsArray.length;i++) {
  1538.                 
  1539.                 if(i==tagsArray.length-1) continue;
  1540.                 
  1541.                 var tag=tagsArray[i].firstChild.nodeValue;
  1542.                     
  1543.                 if(tag.toLowerCase()==collename.toLowerCase()) {
  1544.                     
  1545.                     if(i==tagsArray.length-2) {textLiteral=textLiteral.replace(/,$/,"");}
  1546.                     
  1547.                     continue;
  1548.                     
  1549.                 }
  1550.                 
  1551.                 textLiteral+=tag+(i!=tagsArray.length-2 ? "," : "");
  1552.                 
  1553.             }
  1554.             return textLiteral;
  1555.             
  1556.         },
  1557.                 
  1558.         addImageResourceNodeToLibraryDatabase: function (chosencolname,filename,doc) {
  1559.  
  1560.             var imagename,imagelocation,imagedescription,imageposition,imagetags,imageversion,imageuploaded,imagesiteURI,imagesource,imagescreenRes,imagebackgroundColor;
  1561.         
  1562.             var preSource="";
  1563.             
  1564.             var collename=filename.split("/")[0];
  1565.             
  1566.             if(doc.defaultView.location.href.toString().search(/personasrotator\.com\/persona\/gallery/) !=-1 ){
  1567.                 preSource="site";
  1568.             }
  1569.             
  1570.             if(preSource=="site"){
  1571.                 
  1572.                 imagename = doc.getElementsByClassName("nameForImage")[0].firstChild.nodeValue;
  1573.                 imagelocation =  PersonasRotator.getTheLeafNameFromFileNameString(filename);
  1574.                 imagedescription = doc.getElementsByClassName("personadescription")[0].textContent; 
  1575.                 imageposition = doc.defaultView.wrappedJSObject.PersonasRotatorPose.personasrotatorposition;    
  1576.                 imagetags=collename+","+PersonasRotator.retrieveTagsFromSite(doc,collename);
  1577.                 imageversion="0.1";
  1578.                 imageuploaded="true";
  1579.                 imagesiteURI=doc.defaultView.location.href.toString();
  1580.                 imagesource="site";
  1581.                 imagescreenRes=doc.getElementById("pre_main_screenRes").className;
  1582.                 imagebackgroundColor=doc.getElementById("pre_main_backgroundColor").className;
  1583.                 
  1584.             }
  1585.             
  1586.             else {
  1587.  
  1588.                 imagename = PersonasRotator.getTheLeafNameFromFileNameString(filename).replace(/\.\w+$/,"");
  1589.                 imagelocation = PersonasRotator.getTheLeafNameFromFileNameString(filename);
  1590.                 imagedescription = "undefined";
  1591.                 imageposition = PersonasRotator.retrievePersonaPositionForTheImage(filename);
  1592.                 imagetags=filename.split("/")[0];
  1593.                 imageversion="0.1";
  1594.                 imageuploaded="false";
  1595.                 imagesiteURI="null";
  1596.                 imagesource="external";
  1597.                 imagescreenRes=screen.width+"x"+screen.height;    
  1598.                 imagebackgroundColor=PersonasRotator.retrieveDesktopBackgroundColor();        
  1599.                 
  1600.             }            
  1601.             
  1602.             var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getlibraryfileURI());
  1603.  
  1604.             var newnode=PersonasRotatorRDF.rdfService.GetResource(PersonasRotator.databaseResourceSiteName+PersonasRotator.createEncodedName(filename));
  1605.             
  1606.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#name" ),PersonasRotatorRDF.rdfService.GetLiteral( imagename ),true);
  1607.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#default" ),PersonasRotatorRDF.rdfService.GetLiteral( "false" ),true);
  1608.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#description" ),PersonasRotatorRDF.rdfService.GetLiteral( imagedescription ),true);
  1609.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#location" ),PersonasRotatorRDF.rdfService.GetLiteral( imagelocation ),true);
  1610.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#position" ),PersonasRotatorRDF.rdfService.GetLiteral( imageposition ),true);
  1611.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#tags" ),PersonasRotatorRDF.rdfService.GetLiteral( imagetags ),true);
  1612.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#version" ),PersonasRotatorRDF.rdfService.GetLiteral( imageversion),true);    
  1613.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#uploaded" ),PersonasRotatorRDF.rdfService.GetLiteral( imageuploaded),true);
  1614.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#siteuri" ),PersonasRotatorRDF.rdfService.GetLiteral( imagesiteURI),true);
  1615.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#source" ),PersonasRotatorRDF.rdfService.GetLiteral( imagesource),true);
  1616.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#screenres" ),PersonasRotatorRDF.rdfService.GetLiteral( imagescreenRes),true);
  1617.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#backgroundcolor" ),PersonasRotatorRDF.rdfService.GetLiteral( imagebackgroundColor),true);
  1618.         
  1619.             var mainSeq=PersonasRotatorRDF.rdfContainerUtils.MakeSeq(ds,PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator:"+PersonasRotator.createEncodedName(chosencolname)+"backs"));
  1620.         
  1621.             mainSeq.AppendElement(newnode);
  1622.  
  1623.             ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  1624.  
  1625.         },
  1626.         
  1627.         addImageResourceNodeToCollectionDatabase: function (chosencolname,filename,doc) {
  1628.             
  1629.             var imagename,imagelocation,imagedescription,imageposition,imagetags,imageversion,imageuploaded,imagesiteURI,imagesource,imagescreenRes,imagebackgroundColor;
  1630.         
  1631.             var preSource="";
  1632.             
  1633.             var collename=filename.split("/")[0];
  1634.             
  1635.             if(doc.defaultView.location.href.toString().search(/personasrotator\.com\/persona\/gallery/) !=-1 ){
  1636.                 preSource="site";
  1637.             }
  1638.             
  1639.             if(preSource=="site"){
  1640.                 
  1641.                 imagename = doc.getElementsByClassName("nameForImage")[0].firstChild.nodeValue;
  1642.                 imagelocation = PersonasRotator.getTheLeafNameFromFileNameString(filename);
  1643.                 imagedescription = doc.getElementsByClassName("personadescription")[0].textContent; 
  1644.                 imageposition = doc.defaultView.wrappedJSObject.PersonasRotatorPose.personasrotatorposition;    
  1645.                 imagetags=collename+","+PersonasRotator.retrieveTagsFromSite(doc,collename);
  1646.                 imageversion="0.1";
  1647.                 imageuploaded="true";
  1648.                 imagesiteURI=doc.defaultView.location.href.toString();
  1649.                 imagesource="site";
  1650.                 imagescreenRes=doc.getElementById("pre_main_screenRes").className;
  1651.                 imagebackgroundColor=doc.getElementById("pre_main_backgroundColor").className;
  1652.                 
  1653.             }
  1654.             
  1655.             else {
  1656.  
  1657.                 imagename = PersonasRotator.getTheLeafNameFromFileNameString(filename).replace(/\.\w+$/,"");
  1658.                 imagelocation = PersonasRotator.getTheLeafNameFromFileNameString(filename);
  1659.                 imagedescription = "undefined";
  1660.                 imageposition = PersonasRotator.retrievePersonaPositionForTheImage(filename);
  1661.                 imagetags=filename.split("/")[0];
  1662.                 imageversion="0.1";
  1663.                 imageuploaded="false";
  1664.                 imagesiteURI="null";
  1665.                 imagesource="external";
  1666.                 imagescreenRes=screen.width+"x"+screen.height;        
  1667.                 imagebackgroundColor=PersonasRotator.retrieveDesktopBackgroundColor();        
  1668.                 
  1669.             }            
  1670.         
  1671.             var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getTheURIFromFileName(PersonasRotator.createCollectionRDfFileName(filename)));
  1672.  
  1673.             var newnode=PersonasRotatorRDF.rdfService.GetResource(PersonasRotator.databaseResourceSiteName+PersonasRotator.createEncodedName(filename));
  1674.             
  1675.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#name" ),PersonasRotatorRDF.rdfService.GetLiteral( imagename ),true);
  1676.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#default" ),PersonasRotatorRDF.rdfService.GetLiteral( "false" ),true);
  1677.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#description" ),PersonasRotatorRDF.rdfService.GetLiteral( imagedescription ),true);
  1678.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#location" ),PersonasRotatorRDF.rdfService.GetLiteral( imagelocation ),true);
  1679.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#position" ),PersonasRotatorRDF.rdfService.GetLiteral( imageposition ),true);
  1680.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#tags" ),PersonasRotatorRDF.rdfService.GetLiteral( imagetags ),true);
  1681.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#version" ),PersonasRotatorRDF.rdfService.GetLiteral( imageversion),true);    
  1682.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#uploaded" ),PersonasRotatorRDF.rdfService.GetLiteral( imageuploaded),true);
  1683.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#siteuri" ),PersonasRotatorRDF.rdfService.GetLiteral( imagesiteURI),true);
  1684.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#source" ),PersonasRotatorRDF.rdfService.GetLiteral( imagesource),true);
  1685.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#screenres" ),PersonasRotatorRDF.rdfService.GetLiteral( imagescreenRes),true);
  1686.             ds.Assert(newnode,PersonasRotatorRDF.rdfService.GetResource( "urn:personasrotator#backgroundcolor" ),PersonasRotatorRDF.rdfService.GetLiteral( imagebackgroundColor),true);
  1687.             
  1688.             var mainSeq=PersonasRotatorRDF.rdfContainerUtils.MakeSeq(ds,PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator:"+PersonasRotator.createEncodedName(chosencolname)+"backs"));
  1689.         
  1690.             mainSeq.AppendElement(newnode);
  1691.  
  1692.             ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  1693.  
  1694.         },
  1695.         
  1696.         createCollectionRDfFileName:function(filename) {
  1697.         
  1698.         return filename.split("/")[0]+"/"+"Collection.rdf";
  1699.         
  1700.         },
  1701.         
  1702.         tryToPopulatePersonaWindow : function(chosencolname,filename) {
  1703.             
  1704.             var imagelocation=PersonasRotator.createThumbImageName(filename);
  1705.             
  1706.             var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  1707.                                .getService(Components.interfaces.nsIWindowMediator);
  1708.             var enumerator = wm.getEnumerator(null);
  1709.             
  1710.             while(enumerator.hasMoreElements()) {
  1711.  
  1712.                 var win = enumerator.getNext();
  1713.  
  1714.                 if (win.name=="PersonasRotatorWindow") {
  1715.                     
  1716.                     if (win.document.getElementById(encodeURI(chosencolname)+"button").getAttribute("clicked")=="true") {
  1717.                             
  1718.                         var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getlibraryfileURI());    
  1719.  
  1720.                         var imagenamePredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#name");
  1721.                         var uri=PersonasRotator.databaseResourceSiteName+PersonasRotator.createEncodedName(filename);
  1722.                         var imageResource = PersonasRotatorRDF.rdfService.GetResource(uri);
  1723.  
  1724.                         var imagenametarget=ds.GetTarget(imageResource,imagenamePredicate,true);
  1725.             
  1726.                         if (imagenametarget) {
  1727.                             
  1728.                             var imagename = imagenametarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  1729.  
  1730.                         }        
  1731.                         
  1732.                         var imagewrapperdiv=document.createElementNS("http://www.w3.org/1999/xhtml","html:div");
  1733.                         imagewrapperdiv.setAttribute("class","imagewrapperdiv");
  1734.                         imagewrapperdiv.style.width="180px";
  1735.                         imagewrapperdiv.style.height="155px";
  1736.                         imagewrapperdiv.style.cssFloat="left";
  1737.  
  1738.                         
  1739.                         var namespan = win.document.createElement("box");
  1740.                         namespan.setAttribute("class","serdo imagespan");
  1741.                         namespan.setAttribute("ondblclick","PersonasWindow.ondoubleclick(event)");
  1742.                         namespan.setAttribute("onclick","PersonaWindowSelectManager.clicklistener(event)");
  1743.                         namespan.appendChild(document.createTextNode(imagename));
  1744.                         namespan.setAttribute("style","display:block;color:black;width:142px;height:"+(win.document.defaultView.getComputedStyle(namespan, null).getPropertyValue("line-height"))+";margin-top:-28px;text-align:center;overflow-y:hidden;overflow-x:hidden;padding:0 5px 0 5px;");
  1745.                         var imagenameanchor = namespan;
  1746.  
  1747.                         
  1748.                         var imageelement=document.createElement("image");
  1749.                         imageelement.setAttribute("src",PersonasRotator.assignFileURIToImage(imagelocation));
  1750.                         imageelement.setAttribute("class","personasrotatorimage");
  1751.                         imageelement.setAttribute("onclick","PersonaWindowSelectManager.clicklistener(event)");
  1752.                         
  1753.                         imageelement.setAttribute("tooltiptext",imagename);
  1754.                         imageelement.setAttribute("width","157");
  1755.                         imageelement.setAttribute("height","150");
  1756.                         imageelement.setAttribute("ondblclick","PersonasWindow.ondoubleclick(event)");
  1757.                         imageelement.setAttribute("filename",imagelocation);
  1758.                         
  1759.                         imagewrapperdiv.appendChild(imageelement);
  1760.                         imagewrapperdiv.appendChild(imagenameanchor);
  1761.                         
  1762.                         if(win.document.getElementById(encodeURI(chosencolname)+"button").hasAttribute("fillspaceleft")) {
  1763.                         
  1764.                             if(win.PersonasWindow.fillspacestate && win.PersonasWindow.hasClass(win.document.getElementById(encodeURI(chosencolname)+"htmldiv"),"active")){
  1765.                                 
  1766.                                 win.PersonasWindow.fillspacebackuparray.push(imagewrapperdiv);
  1767.                                 
  1768.                             }
  1769.     
  1770.                         }
  1771.                         
  1772.                         else {
  1773.                             
  1774.                             if(win.PersonasWindow.fillspacestate && win.PersonasWindow.hasClass(win.document.getElementById(encodeURI(chosencolname)+"htmldiv"),"active")){
  1775.                                 
  1776.                                 win.PersonasWindow.fillspacebackuparray.push(imagewrapperdiv);
  1777.                                 
  1778.                             }
  1779.                                             
  1780.                             else if(!win.PersonasWindow.fillspacestate && win.PersonasWindow.hasClass(win.document.getElementById(encodeURI(chosencolname)+"htmldiv"),"active")){
  1781.                                 
  1782.                                 win.document.getElementById(encodeURI(chosencolname)+"htmldiv").appendChild(imagewrapperdiv);
  1783.                                 
  1784.                             }                            
  1785.                                                                     
  1786.                             else if(win.PersonasWindow.fillspacestate && !win.PersonasWindow.hasClass(win.document.getElementById(encodeURI(chosencolname)+"htmldiv"),"active")){
  1787.  
  1788.                                 win.document.getElementById(encodeURI(chosencolname)+"htmldiv").appendChild(imagewrapperdiv);
  1789.                                 
  1790.                             }                            
  1791.                                                                                     
  1792.                             else if(!win.PersonasWindow.fillspacestate && !win.PersonasWindow.hasClass(win.document.getElementById(encodeURI(chosencolname)+"htmldiv"),"active")){
  1793.                                 
  1794.                                 win.document.getElementById(encodeURI(chosencolname)+"htmldiv").appendChild(imagewrapperdiv);
  1795.                                 
  1796.                             }                            
  1797.                             
  1798.                         }
  1799.                     
  1800.                     }
  1801.  
  1802.                 }
  1803.  
  1804.             }
  1805.         
  1806.         },
  1807.         
  1808.         refreshPreviewTabsArray:function() {
  1809.         
  1810.             PersonasRotator.previewtabscopy=[];
  1811.             
  1812.             for (var i=0;i<PersonasRotator.previewtabs.length;i++) {
  1813.             
  1814.                 if (gBrowser.selectedTab==PersonasRotator.previewtabs[i]) {continue;}
  1815.                 else {PersonasRotator.previewtabscopy.push(PersonasRotator.previewtabs[i])}
  1816.             
  1817.             }
  1818.             
  1819.             if (PersonasRotator.previewtabs.length==1) PersonasRotator.previewtabs=[];
  1820.             else PersonasRotator.previewtabs=PersonasRotator.previewtabscopy;
  1821.  
  1822.         },
  1823.  
  1824.         showUploadOneTimeAlert:function(){
  1825.             
  1826.             var personasrotatorprefsinstance = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  1827.  
  1828.             var personasrotatoruploadonetimealertshowable = personasrotatorprefsinstance.getBoolPref("extensions.personasrotator.uploadonetimealertshowable");
  1829.  
  1830.             if (personasrotatoruploadonetimealertshowable) {
  1831.  
  1832.                 var check = {value: false};
  1833.  
  1834.                 var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  1835.                                         
  1836.                 prompt.alertCheck(null,"Personas Rotator",PersonasRotator.STRINGS.getString("uploadOneTimeAlertWarning"),PersonasRotator.STRINGS.getString("dontShowAgain"),check);
  1837.  
  1838.                 if(check.value){
  1839.  
  1840.                     personasrotatorprefsinstance.setBoolPref("extensions.personasrotator.uploadonetimealertshowable", false);
  1841.  
  1842.                 }
  1843.                         
  1844.             }
  1845.                 
  1846.         },            
  1847.         
  1848.         uploadPersona:function(event,doc){
  1849.             
  1850.             var filename=PersonasRotator.retrievetabpersonaimage(doc);
  1851.             
  1852.             if (filename==undefined || filename==null ) {PersonasRotator.createAlertPrompt(PersonasRotator.STRINGS.getFormattedString("noPersona",["upload"]));return} 
  1853.             
  1854.             var personaNsiFile=PersonasRotator.getChromeFile(filename);
  1855.             
  1856.             try{
  1857.             if(personaNsiFile.fileSize>600*1024){PersonasRotator.createAlertPrompt(PersonasRotator.STRINGS.getFormattedString("overSizedWarning",[parseInt(personaNsiFile.fileSize/1024)]));return;};
  1858.             }
  1859.             catch(err){
  1860.                 PersonasRotator.createAlertPrompt(PersonasRotator.STRINGS.getString("alreadyDeleted"));
  1861.                 return;
  1862.             }
  1863.             
  1864.             var leafName=PersonasRotator.getTheLeafNameFromFileNameString(filename);
  1865.                         
  1866.             var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getlibraryfileURI());    
  1867.  
  1868.             var uri=PersonasRotator.databaseResourceSiteName+PersonasRotator.createEncodedName(filename);
  1869.  
  1870.             var imageResource = PersonasRotatorRDF.rdfService.GetResource(uri);
  1871.             
  1872.             var imageuploadedPredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#uploaded");
  1873.             var imageuploadedtarget=ds.GetTarget(imageResource,imageuploadedPredicate,true);
  1874.             if (imageuploadedtarget) {
  1875.                 var imageuploaded = imageuploadedtarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  1876.             }    
  1877.             doc.defaultView.personasrotatoruploaded=imageuploaded;
  1878.             
  1879.             if(imageuploaded=="true"){
  1880.  
  1881.             if(PersonasRotator.createConfirmPrompt(PersonasRotator.STRINGS.getString("alreadyUploaded"))) {
  1882.  
  1883.                 PersonasRotator.visitPersonaPage(event,doc);
  1884.  
  1885.             }
  1886.  
  1887.             return;
  1888.  
  1889.             }
  1890.         
  1891.             var imagenamePredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#name");
  1892.             var imagenametarget=ds.GetTarget(imageResource,imagenamePredicate,true);
  1893.             if (imagenametarget) {
  1894.                 var imagename = imagenametarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  1895.             }                            
  1896.             doc.defaultView.personasrotatorname=imagename;
  1897.         
  1898.             var imagetagsPredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#tags");
  1899.             var imagetagstarget=ds.GetTarget(imageResource,imagetagsPredicate,true);
  1900.             if (imagetagstarget) {
  1901.                 var imagetags = imagetagstarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  1902.             }                            
  1903.             doc.defaultView.personasrotatortags=imagetags;            
  1904.         
  1905.             var imagedescriptionPredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#description");
  1906.             var imagedescriptiontarget=ds.GetTarget(imageResource,imagedescriptionPredicate,true);
  1907.             if (imagedescriptiontarget) {
  1908.                 var imagedescription = imagedescriptiontarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  1909.             }                            
  1910.             doc.defaultView.personasrotatordescription=imagedescription;                
  1911.             
  1912.             var imagepositionPredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#position");
  1913.             var imagepositiontarget=ds.GetTarget(imageResource,imagepositionPredicate,true);
  1914.             if (imagepositiontarget) {
  1915.                 var imageposition = imagepositiontarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  1916.             }                            
  1917.             doc.defaultView.personasrotatorposition=imageposition;
  1918.             
  1919.             var imagebackgroundColorPredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#backgroundcolor");
  1920.             var imagebackgroundColortarget=ds.GetTarget(imageResource,imagebackgroundColorPredicate,true);
  1921.             if (imagebackgroundColortarget) {
  1922.                 var imagebackgroundColor = imagebackgroundColortarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  1923.             }                            
  1924.             doc.defaultView.personasrotatorbackgroundColor=imagebackgroundColor;
  1925.         
  1926.             var ios = Components.classes["@mozilla.org/network/io-service;1"]
  1927.             .getService(Components.interfaces.nsIIOService);
  1928.             var uri = ios.newURI("http://personasrotator.com/", null, null);
  1929.             var cookieSvc =
  1930.                Components.classes["@mozilla.org/cookieService;1"]
  1931.                          .getService(Components.interfaces.nsICookieService);
  1932.             var cookie = cookieSvc.getCookieString(uri, null);
  1933.             
  1934.             if (cookie!=null && cookie.indexOf("memberID=")!=-1) {
  1935.             
  1936.                 var medProfId=cookie.split("memberID=")[1].split(";")[0];
  1937.                 
  1938.             }
  1939.             
  1940.             else {
  1941.             
  1942.                 if(PersonasRotator.createConfirmPrompt(PersonasRotator.STRINGS.getString("logInWarning"))) {
  1943.                 
  1944.                     window.gBrowser.selectedTab = window.gBrowser.addTab("http://personasrotator.com/member.php");
  1945.                     return ;
  1946.                     
  1947.                 }
  1948.                 
  1949.                 else {
  1950.                 
  1951.                     return;
  1952.                 
  1953.                 }
  1954.             
  1955.             }
  1956.  
  1957.             var personasrotatorprefsinstance = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  1958.             var prefilluploadform = personasrotatorprefsinstance.getBoolPref("extensions.personasrotator.prefilluploadform");
  1959.             
  1960.             doc.removeEventListener("mousedown",PersonasRotator.mouseclickondocument,false);
  1961.             doc.removeEventListener("mouseup",PersonasRotator.mouseupondocument,false);
  1962.             
  1963.             PersonasRotator.showUploadOneTimeAlert();
  1964.         
  1965.             var MIMEService = Components.classes["@mozilla.org/mime;1"] .getService(Components.interfaces.nsIMIMEService);
  1966.             
  1967.             var personaMIMEType=MIMEService.getTypeFromFile(personaNsiFile);
  1968.             
  1969.             var formtext='<div id="paddingtopdiv">'
  1970.             +'<div id="personasrotatoruploadform">'
  1971.             +'<form id="form" name="form" method="post" enctype="multipart/form-data">'
  1972.             +'<span  id="closeanchor" title="Close the upload form">Close</span>'
  1973.             +'<span id="uploadheading">Upload form</span>'
  1974.             +'<p>Please fill out the form below before you upload</p>'
  1975.             +'<label>Name<span class="tip">Add persona name</span></label>'
  1976.             +'<input type="text" name="title" id="personaname" value="'+(!prefilluploadform ? "" : imagename)+'"/><span class="tooltipicons" id="nametooltipicon">Tooltip</span>'
  1977.             +'<label>Tags<span class="tip">Add persona tags</span></label>'
  1978.             +'<input type="text" name="tags" id="personatags" value="'+(!prefilluploadform ? "" : imagetags)+'"/><span class="tooltipicons" id="tagtooltipicon">Tooltip</span>'
  1979.             +'<label>Description<span class="tip">Add persona description</span></label>'
  1980.             +'<textarea type="text" name="description" id="personadescription" >'+(!prefilluploadform ? "" : ((imagedescription=="undefined") ? "" : imagedescription))+'</textarea>'
  1981.             +'<span class="tooltipicons" id="descriptiontooltipicon">Tooltip</span>'
  1982.             +'<input type="hidden" id="position" name="position" value="'+imageposition+'"/>'
  1983.             +'<input type="hidden" id="screenRes" name="screenRes" value="'+screen.width+"x"+screen.height+'"/>'
  1984.             +'<input type="hidden" id="backgroundColor" name="backgroundColor" value="'+imagebackgroundColor+'"/>'
  1985.             +'<input type="hidden" value="'+medProfId+'" id="medProfId" name="medProfId"/>'
  1986.             +'<input type="file" id="personafile" name="uploadFile" />'
  1987.             +'<button type="submit" id="submitbutton" name="upload">Upload</button>'
  1988.             +'</form>'
  1989.             +'</div>'
  1990.             +'</div>';
  1991.             
  1992.             var tooltiptext='<div class="tooltipdivs" id="nametooltipdiv"><p>'+PersonasRotator.STRINGS.getString("nameDescription")+'</p></div><div class="tooltipdivs" id="tagtooltipdiv"><p>'+PersonasRotator.STRINGS.getString("tagDescription")+'</p></div><div class="tooltipdivs" id="descriptiontooltipdiv"><p>'+PersonasRotator.STRINGS.getString("descriptionDescription")+'</p></div>';
  1993.             
  1994.             doc.body.innerHTML=formtext+tooltiptext;
  1995.             
  1996.             doc.defaultView.personaRotator={personaMIMEType:personaMIMEType};
  1997.         
  1998.             var createdAjaxScript=doc.createElement("script");
  1999.             
  2000.             createdAjaxScript.setAttribute("type","text/javascript");
  2001.             
  2002.             createdAjaxScript.setAttribute("src","chrome://personasrotator/content/ajaxUpload.js");
  2003.             
  2004.             doc.body.appendChild(createdAjaxScript);            
  2005.             
  2006.             PersonasRotator.addClass(doc.body,"uploadformshowing");
  2007.             
  2008.             var bodyheight=doc.body.clientHeight;
  2009.  
  2010.             var formheight=275;
  2011.  
  2012.             doc.getElementById("personafile").value=personaNsiFile.path;
  2013.  
  2014.             doc.getElementById("personasrotatoruploadform").style.marginTop=((bodyheight-formheight)*0.5)+"px";
  2015.  
  2016.             doc.getElementById("closeanchor").addEventListener("click",function(event){
  2017.  
  2018.                 this.ownerDocument.body.innerHTML="";
  2019.                 PersonasRotator.removeClass(doc.body,"uploadformshowing");
  2020.             
  2021.                 doc.addEventListener("mousedown",PersonasRotator.mouseclickondocument,false);
  2022.                 doc.addEventListener("mouseup",PersonasRotator.mouseupondocument,false);
  2023.                 
  2024.                 event.preventDefault();
  2025.                 
  2026.             },false);
  2027.                                             
  2028.             doc.addEventListener("personasrotatorUploadedTrue",PersonasRotator.handleAfterPersonaUploadRequirements,false);
  2029.  
  2030.         },
  2031.  
  2032.         handleAfterPersonaUploadRequirements:function(event){
  2033.                 
  2034.             var doc;
  2035.         
  2036.             if (event.target.nodeName=="#document") {
  2037.             
  2038.                 doc=event.target;
  2039.                 
  2040.                 try {
  2041.                     var documentURI=doc.documentURI;
  2042.                 } catch (err) {
  2043.                     return;
  2044.                 }
  2045.                 if (!documentURI) {
  2046.                     
  2047.                     PersonasRotator.createAlertPrompt("documentURI"+" is problematic");
  2048.                 }
  2049.  
  2050.                 if (documentURI == "chrome://personasrotator/content/wr.html") {
  2051.                                         
  2052.                     var filename=PersonasRotator.retrievetabpersonaimage(doc);
  2053.                     
  2054.                     var retrievedSiteURI=doc.defaultView.personasrotatorretrievedSiteURI;
  2055.  
  2056.                     PersonasRotator.updatePredicates("Individual",{uploaded:"true",source:"upload",siteuri:retrievedSiteURI},filename,doc);
  2057.                     PersonasRotator.updatePredicates("Library",{uploaded:"true",source:"upload",siteuri:retrievedSiteURI},filename,doc);
  2058.                     PersonasRotator.updatePredicates("Collection",{uploaded:"true",source:"upload",siteuri:retrievedSiteURI},filename,doc);
  2059.  
  2060.                     var redirectionScript=doc.createElement("script");
  2061.                     redirectionScript.setAttribute("type","text/javascript");
  2062.                     redirectionScript.innerHTML="window.location='"+retrievedSiteURI+"';";
  2063.                     doc.body.appendChild(redirectionScript);
  2064.                     
  2065.                 }
  2066.             
  2067.             }
  2068.         
  2069.         },
  2070.     
  2071.         morelikethis:function(event,doc){
  2072.  
  2073.             var filename=PersonasRotator.retrievetabpersonaimage(doc);
  2074.             
  2075.             var leafName=filename.split("/")[0];
  2076.  
  2077.             gBrowser.selectedTab = gBrowser.addTab('http://personasrotator.com/persona/gallery_tag/'+encodeURIComponent(leafName));
  2078.         
  2079.         },
  2080.                 
  2081.         visitPersonaPage:function(event,doc){
  2082.         
  2083.             var filename=PersonasRotator.retrievetabpersonaimage(doc);
  2084.             
  2085.             if (filename==undefined || filename==null ) {PersonasRotator.createAlertPrompt(PersonasRotator.STRINGS.getFormattedString("noPersona",["visit"]));return;}
  2086.             
  2087.             var leafName=PersonasRotator.getTheLeafNameFromFileNameString(filename);
  2088.             
  2089.             var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getlibraryfileURI());    
  2090.  
  2091.             var uri=PersonasRotator.databaseResourceSiteName+PersonasRotator.createEncodedName(filename);
  2092.             
  2093.             var imageResource = PersonasRotatorRDF.rdfService.GetResource(uri);
  2094.             
  2095.             var imagesourcePredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#source");
  2096.             var imagesourcetarget=ds.GetTarget(imageResource,imagesourcePredicate,true);
  2097.             if (imagesourcetarget) {
  2098.                 var imagesource = imagesourcetarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  2099.             }    
  2100.             else {
  2101.                 PersonasRotator.createAlertPrompt(PersonasRotator.STRINGS.getString("alreadyDeleted"));
  2102.                 return;
  2103.             }
  2104.             
  2105.             if(imagesource=="site"||imagesource=="upload"){
  2106.                 
  2107.                 var imagesiteuriPredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#siteuri");
  2108.                 var imagesiteuritarget=ds.GetTarget(imageResource,imagesiteuriPredicate,true);
  2109.                 if (imagesiteuritarget) {
  2110.                     var imagesiteuri = imagesiteuritarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  2111.                 }                            
  2112.                 
  2113.                 gBrowser.selectedTab = gBrowser.addTab(imagesiteuri);
  2114.                 
  2115.             }
  2116.             
  2117.             else {
  2118.                 
  2119.                 PersonasRotator.createAlertPrompt(PersonasRotator.STRINGS.getString("onlyPRPersonas"));
  2120.                 
  2121.             }
  2122.             
  2123.         },
  2124.         
  2125.         createAlertPrompt:function(promptString){
  2126.             
  2127.             var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  2128.                                     .getService(Components.interfaces.nsIPromptService);
  2129.                                     
  2130.             prompt.alert(null, "Personas Rotator",promptString);
  2131.         
  2132.         },
  2133.         
  2134.         createConfirmPrompt:function(promptString){
  2135.             
  2136.             var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  2137.                                     .getService(Components.interfaces.nsIPromptService);            
  2138.             
  2139.             return prompt.confirm(null, "Personas Rotator",promptString);
  2140.  
  2141.         },
  2142.         
  2143.         installMoreOpen:function(){
  2144.         
  2145.             gBrowser.selectedTab = gBrowser.addTab('http://personasrotator.com/persona/gallery_tag/'+screen.width+'x'+screen.height+'?imo');
  2146.         
  2147.         },
  2148.         
  2149.         PersonasRotatorWindowChecknOpen:function() {
  2150.             
  2151.             var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  2152.                                .getService(Components.interfaces.nsIWindowMediator);
  2153.             var enumerator = wm.getEnumerator(null);
  2154.             
  2155.             var win;
  2156.             
  2157.             while(enumerator.hasMoreElements()) {
  2158.  
  2159.                 win = enumerator.getNext();
  2160.  
  2161.                 if (win.name=="PersonasRotatorWindow") {
  2162.  
  2163.                     win.focus();
  2164.                     return;
  2165.                     
  2166.                 }
  2167.  
  2168.             }
  2169.     
  2170.              window.openDialog('chrome://personasrotator/content/personas.xul','PersonasRotatorWindow','chrome,close=yes,minimizable=yes,centerscreen');
  2171.              
  2172.         },
  2173.  
  2174.         createEncodedName:function(passedDecodedName){
  2175.         
  2176.         if(passedDecodedName==undefined) return;
  2177.     
  2178.             var namesplitarray=passedDecodedName.split("/");
  2179.             
  2180.             var encodedname="";
  2181.             
  2182.             for (var i=0;i<namesplitarray.length;i++) {
  2183.             
  2184.                 encodedname+=encodeURI(namesplitarray[i]);
  2185.                 encodedname+=(i!=namesplitarray.length-1) ? "/" : "";
  2186.         
  2187.             }
  2188.             
  2189.             return encodedname;    
  2190.         
  2191.         },
  2192.         
  2193.         createDecodedName:function(passedEncodedName){
  2194.         
  2195.         if(passedEncodedName==undefined) return;
  2196.  
  2197.             var namesplitarray=passedEncodedName.split("/");
  2198.             
  2199.             var decodedname="";
  2200.             
  2201.             for (var i=0;i<namesplitarray.length;i++) {
  2202.         
  2203.                 decodedname+=decodeURI(namesplitarray[i]);
  2204.                 decodedname+=((i!=namesplitarray.length-1) ? "/" : "");
  2205.             
  2206.             }
  2207.     
  2208.             return decodedname;
  2209.     
  2210.         },
  2211.             
  2212.         getMainPersonaDirectoryFileURL:function() {
  2213.  
  2214.             var file = Components.classes["@mozilla.org/file/directory_service;1"]
  2215.                                  .getService(Components.interfaces.nsIProperties)
  2216.                                  .get("ProfD", Components.interfaces.nsIFile);
  2217.  
  2218.             file.append("personasrotator");
  2219.                         
  2220.             var ios = Components.classes["@mozilla.org/network/io-service;1"]
  2221.                                 .getService(Components.interfaces.nsIIOService);
  2222.             var URL = ios.newFileURI(file);
  2223.             
  2224.  
  2225.             return URL.spec;
  2226.     
  2227.         },
  2228.         
  2229.         browserOpenNews:function (event) {
  2230.             
  2231.                 if (true) {
  2232.                     var newTab = gBrowser.loadOneTab("chrome://personasrotator/content/cc.html", null, null, null, false, false);
  2233.                     newTab.linkedBrowser.userTypedValue = undefined;
  2234.                     if (gURLBar) {
  2235.                         setTimeout(function () {gURLBar.focus();}, 0);
  2236.                     }
  2237.                 } else {
  2238.                     window.originalBrowserOpenTab(event);
  2239.                 }
  2240.                 
  2241.         },
  2242.         
  2243.         bringNews:function(){
  2244.  
  2245.             window.BrowserOpenTab=PersonasRotator.browserOpenNews; 
  2246.     
  2247.         },
  2248.         
  2249.         browserOpenTab:function (event) {
  2250.                 
  2251.             if (true) {
  2252.             
  2253.                 var newTab = gBrowser.loadOneTab(PersonasRotator.openTabURI, null, null, null, false, false);
  2254.                 
  2255.                 newTab.linkedBrowser.userTypedValue = undefined;
  2256.                 
  2257.                 if (gURLBar) {
  2258.                 
  2259.                     setTimeout(function () {gURLBar.focus();}, 0);
  2260.                     
  2261.                 }
  2262.                 
  2263.             } else {
  2264.             
  2265.                 window.originalBrowserOpenTab(event);
  2266.                 
  2267.             }
  2268.                 
  2269.         },
  2270.         
  2271.         bringPersonas:function(){
  2272.             
  2273.             if(window.TMP_BrowserOpenTab){
  2274.             
  2275.               getBrowser().removeEventListener("NewTab", window.TMP_BrowserOpenTab, true);
  2276.               
  2277.               window.originalBrowserOpenTab = window.TMP_BrowserOpenTab;
  2278.               
  2279.               window.TMP_BrowserOpenTab = PersonasRotator.browserOpenTab;
  2280.               
  2281.               getBrowser().addEventListener("NewTab", window.TMP_BrowserOpenTab, true);
  2282.               
  2283.             } 
  2284.             
  2285.             else if (window.TBP_BrowserOpenTab) {
  2286.             
  2287.               getBrowser().removeEventListener("NewTab", window.TBP_BrowserOpenTab, true);
  2288.               
  2289.               window.originalBrowserOpenTab = window.TBP_BrowserOpenTab;
  2290.               
  2291.               window.TBP_BrowserOpenTab = PersonasRotator.browserOpenTab;
  2292.               
  2293.               getBrowser().addEventListener("NewTab", window.TBP_BrowserOpenTab, true);
  2294.               
  2295.             } 
  2296.             
  2297.             else {
  2298.             
  2299.               getBrowser().removeEventListener("NewTab", window.BrowserOpenTab, false);
  2300.               
  2301.               window.originalBrowserOpenTab = window.BrowserOpenTab;
  2302.               
  2303.               window.BrowserOpenTab = PersonasRotator.browserOpenTab;
  2304.               
  2305.               getBrowser().addEventListener("NewTab", window.BrowserOpenTab, false);
  2306.               
  2307.             }
  2308.  
  2309.         },
  2310.         
  2311.         prepareForNewsTab:function(){
  2312.  
  2313.             PersonasRotator.bringNews();
  2314.         
  2315.         },
  2316.         
  2317.         createDecodedNameFromFileURI:function(passedEncodedFileURIName){
  2318.  
  2319.             var namesplitarray=passedEncodedFileURIName.split("/");
  2320.             
  2321.             var decodedname="";
  2322.             
  2323.             for (var i=0;i<namesplitarray.length;i++) {
  2324.             
  2325.             var mainPersonaDirectoryFileURL=PersonasRotator.getMainPersonaDirectoryFileURL();
  2326.  
  2327.             
  2328.             var io = Components.classes["@mozilla.org/network/io-service;1"]
  2329.                          .getService(Components.interfaces.nsIIOService);
  2330.  
  2331.             var URL=io.newURI(mainPersonaDirectoryFileURL+namesplitarray[i], "UTF8", null);
  2332.  
  2333.  
  2334.             
  2335.             var file = URL.QueryInterface(Components.interfaces.nsIFileURL)
  2336.                           .file;
  2337.             
  2338.             decodedname+=file.leafName+((i!=namesplitarray.length-1) ? "/" : "");
  2339.             
  2340.             }
  2341.             
  2342.             return decodedname;
  2343.  
  2344.         },
  2345.  
  2346.         URLBarSetURI: URLBarSetURI,
  2347.         
  2348.         newURLBarSetURI: function (uri, valid) {
  2349.             
  2350.             if (!uri || !(new RegExp("chrome://personasrotator/content/wr.html")).test(uri.spec)) {
  2351.                 
  2352.                 return PersonasRotator.URLBarSetURI(uri, valid);
  2353.             
  2354.             }
  2355.             
  2356.             var nsiUri = Components.classes['@mozilla.org/network/simple-uri;1'].createInstance(Components.interfaces.nsIURI);
  2357.             nsiUri.spec = "about:blank";
  2358.             PersonasRotator.URLBarSetURI(nsiUri);
  2359.             SetPageProxyState("valid");
  2360.             
  2361.         },            
  2362.         
  2363.         updatePredicates:function(database,hash,filename,doc){
  2364.  
  2365.             var ds;
  2366.             
  2367.             if(database=="Individual"){
  2368.             
  2369.             ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getTheURIFromFileName(PersonasRotator.createIndividualRDFFilename(filename)));
  2370.         
  2371.             }
  2372.             
  2373.             if(database=="Library"){    
  2374.             
  2375.             ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getlibraryfileURI());    
  2376.             
  2377.             }    
  2378.  
  2379.             if(database=="Collection"){    
  2380.         
  2381.             ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotator.getTheURIFromFileName(PersonasRotator.createCollectionRDfFileName(filename)));
  2382.             
  2383.             }
  2384.             
  2385.             var leafName=PersonasRotator.getTheLeafNameFromFileNameString(filename);
  2386.  
  2387.             var theImageNode = PersonasRotatorRDF.rdfService.GetResource(PersonasRotator.databaseResourceSiteName+PersonasRotator.createEncodedName(filename));
  2388.             
  2389.             var updatePredicateName;
  2390.             
  2391.             for (var property in hash){
  2392.             
  2393.                 updatePredicateName=property;
  2394.                 
  2395.                 var updatePredicate=PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#"+updatePredicateName);                
  2396.             
  2397.                 var updatetarget=ds.GetTarget(theImageNode,updatePredicate,true);
  2398.                 
  2399.                 if (updatetarget!=null) var updateTargetValue= updatetarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  2400.                 else {return}                
  2401.                 
  2402.                 var newUpdateTargetValue=hash[property];
  2403.                 
  2404.                 var predicate=PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#"+updatePredicateName);
  2405.                 var oldtarget=PersonasRotatorRDF.rdfService.GetLiteral(updateTargetValue);
  2406.                 var newtarget=PersonasRotatorRDF.rdfService.GetLiteral(newUpdateTargetValue);    
  2407.                 
  2408.                 ds.Change(theImageNode,predicate,oldtarget,newtarget);
  2409.                 
  2410.             }
  2411.             
  2412.             try{
  2413.             ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();                    
  2414.             }
  2415.             catch(err){
  2416.             
  2417.             }
  2418.  
  2419.         },
  2420.     
  2421.         findTheHorizontalCenterOfTheImage:function(imagewidth){
  2422.  
  2423.             return imagewidth*(0.5);
  2424.         
  2425.         },
  2426.  
  2427.         findTheHorizontalCenterOfTheScreen:function(paddingnode){
  2428.         
  2429.             return paddingnode.clientWidth*(0.5);
  2430.         
  2431.         },
  2432.  
  2433.         findHorizontalPositionOffset:function(image,imagewidth,paddingnode){
  2434.         
  2435.             return PersonasRotator.findTheHorizontalCenterOfTheScreen(paddingnode)-PersonasRotator.findTheHorizontalCenterOfTheImage(imagewidth);
  2436.                         
  2437.         },
  2438.  
  2439.         findTheVerticalCenterOfTheImage:function(imageheight){
  2440.         
  2441.             return imageheight*(0.5);
  2442.         
  2443.         },
  2444.  
  2445.         findTheVerticalCenterOfTheScreen:function(paddingnode){
  2446.  
  2447.             return paddingnode.clientHeight*(0.5);
  2448.         
  2449.         },
  2450.  
  2451.         findVerticalPositionOffset:function(image,imageheight,paddingnode){
  2452.  
  2453.             return PersonasRotator.findTheVerticalCenterOfTheScreen(paddingnode)-PersonasRotator.findTheVerticalCenterOfTheImage(imageheight);
  2454.         
  2455.         },
  2456.         
  2457.         //ADDED ONES
  2458.         
  2459.         requestDesktopPersonaChange:function(){
  2460.             
  2461.             PersonasRotator.changeDesktopPersona();
  2462.         
  2463.         },
  2464.     
  2465.         changeDesktopPersona:function(previewRequestObject){
  2466.  
  2467.             var deskWall=new Image();
  2468.  
  2469.             if(previewRequestObject!=null) {
  2470.             
  2471.                 PersonasRotator.imagespecified="yes";
  2472.                 if(previewRequestObject.filename) PersonasRotator.currentimagefilename=previewRequestObject.filename;
  2473.             
  2474.             }
  2475.             
  2476.             if(PersonasRotator.imagespecified=="no"){
  2477.             
  2478.                 if (PersonasRotator.currentarrayindex<PersonasRotator.personasrotator.length) {
  2479.  
  2480.                     PersonasRotator.currentimagefilename=PersonasRotator.personasrotator[PersonasRotator.currentarrayindex];
  2481.                     PersonasRotator.currentarrayindex++;
  2482.  
  2483.                 }
  2484.  
  2485.                 else {
  2486.  
  2487.                     PersonasRotator.currentarrayindex=0;
  2488.                     PersonasRotator.currentimagefilename=PersonasRotator.personasrotator[PersonasRotator.currentarrayindex];
  2489.                     PersonasRotator.currentarrayindex++;
  2490.  
  2491.                 }
  2492.                 
  2493.                 PersonasRotator.writelastimageindex();
  2494.             
  2495.             }
  2496.             
  2497.             if(PersonasRotator.imagespecified!="no") PersonasRotator.imagespecified="no";            
  2498.             
  2499.             if (previewRequestObject==null){
  2500.             
  2501.                 deskWall.src=PersonasRotator.assignFileURIToImage(PersonasRotator.currentimagefilename);
  2502.             
  2503.             }    
  2504.             
  2505.             else if(previewRequestObject!=null){
  2506.             
  2507.                 deskWall.src=(previewRequestObject.filename!=null) ? PersonasRotator.assignFileURIToImage(PersonasRotator.currentimagefilename) : previewRequestObject.url;
  2508.             
  2509.             }
  2510.  
  2511.             deskWall.onload=function() {
  2512.                 
  2513.                 try {
  2514.  
  2515.                     if(previewRequestObject==null){
  2516.                         
  2517.                         var personaDesktopBackgroundColor=parseInt(PersonasRotator.retrievePersonaBackgroundColorForTheImage(PersonasRotator.currentimagefilename));
  2518.                         
  2519.                         if(PersonasRotator._shell.desktopBackgroundColor!=personaDesktopBackgroundColor) PersonasRotator._shell.desktopBackgroundColor=personaDesktopBackgroundColor;
  2520.  
  2521.                         PersonasRotator._shell.setDesktopBackground(deskWall,Components.interfaces.nsIShellService["BACKGROUND_" + PersonasRotator.retrievePersonaPositionForTheImage(PersonasRotator.currentimagefilename)]);
  2522.         
  2523.                     }
  2524.                     
  2525.                     else if (previewRequestObject!=null) {
  2526.                         
  2527.                         if(previewRequestObject.filename==null){
  2528.                         
  2529.                             var personaDesktopBackgroundColor=parseInt(previewRequestObject.backgroundColor);
  2530.                         
  2531.                             if(PersonasRotator._shell.desktopBackgroundColor!=personaDesktopBackgroundColor) PersonasRotator._shell.desktopBackgroundColor=personaDesktopBackgroundColor;
  2532.  
  2533.                             PersonasRotator._shell.setDesktopBackground(deskWall,Components.interfaces.nsIShellService["BACKGROUND_" + previewRequestObject.position]);
  2534.                 
  2535.                         }
  2536.                         
  2537.                         else if(previewRequestObject.filename!=null){
  2538.                         
  2539.                             var personaDesktopBackgroundColor=parseInt(PersonasRotator.retrievePersonaBackgroundColorForTheImage(PersonasRotator.currentimagefilename));
  2540.                         
  2541.                             if(PersonasRotator._shell.desktopBackgroundColor!=personaDesktopBackgroundColor) PersonasRotator._shell.desktopBackgroundColor=personaDesktopBackgroundColor;
  2542.  
  2543.                             PersonasRotator._shell.setDesktopBackground(deskWall,Components.interfaces.nsIShellService["BACKGROUND_" + PersonasRotator.retrievePersonaPositionForTheImage(PersonasRotator.currentimagefilename)]);
  2544.                         
  2545.                         }
  2546.                     
  2547.                     }
  2548.                     
  2549.                 }
  2550.                 
  2551.                 catch(err){
  2552.                 /*
  2553.                     var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
  2554.  
  2555.                     var bb="ERROR:"+"\n"+"deskwallSRC: "+deskWall.src+"\n"+"Index: "+PersonasRotator.currentarrayindex+"\n"+"NewSRC: "+PersonasRotator.newimage.src;                  
  2556.  
  2557.                     aConsoleService.logStringMessage(bb);
  2558.                 */
  2559.                 }
  2560.             
  2561.             }
  2562.  
  2563.             if (PersonasRotator.currentarrayindex==PersonasRotator.personasrotator.length ) {
  2564.             
  2565.                 PersonasRotator.newimage.src=PersonasRotator.assignFileURIToImage(PersonasRotator.personasrotator[0]);
  2566.                 
  2567.             }
  2568.  
  2569.             else {
  2570.  
  2571.                 PersonasRotator.newimage.src=PersonasRotator.assignFileURIToImage(PersonasRotator.personasrotator[PersonasRotator.currentarrayindex]);
  2572.                 
  2573.             }
  2574.             
  2575.         /*
  2576.             var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
  2577.  
  2578.             var bb="deskwallSRC: "+deskWall.src+"\n"+"Index: "+PersonasRotator.currentarrayindex+"\n"+"NewSRC: "+PersonasRotator.newimage.src;                  
  2579.  
  2580.             aConsoleService.logStringMessage(bb);
  2581.         */
  2582.         
  2583.         },
  2584.  
  2585.         enableRotation:function(source){
  2586.  
  2587.             if(source==null) PersonasRotator.changeMenuOptionForEnableRotation();
  2588.             
  2589.             var personasrotatorprefsinstance = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);        
  2590.             var personasrotatorrotationinterval = personasrotatorprefsinstance.getIntPref("extensions.personasrotator.rotationinterval");
  2591.             PersonasRotator.PR.initializeTimer(personasrotatorrotationinterval,true);
  2592.  
  2593.         },
  2594.         
  2595.         changeMenuOptionForEnableRotation:function(){
  2596.             
  2597.             var personasrotatorprefsinstance = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);        
  2598.             var rotationenabled = personasrotatorprefsinstance.getBoolPref("extensions.personasrotator.rotationenabled");
  2599.             
  2600.             var sss = Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService);
  2601.             var ios = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);
  2602.             var css = "@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);#personasrotator-"+("enable")+"rotation{display:none !important;}";
  2603.             var css2 = "@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);#personasrotator-"+("disable")+"rotation{display:none !important;}";
  2604.             var uri = ios.newURI("data:text/css," + css, null, null);
  2605.             var uri2 = ios.newURI("data:text/css," + css2, null, null);
  2606.             
  2607.             if (sss.sheetRegistered(uri2, sss.USER_SHEET)) {
  2608.                 sss.unregisterSheet(uri2, sss.USER_SHEET);
  2609.             }
  2610.             
  2611.             if (!sss.sheetRegistered(uri, sss.USER_SHEET)) {
  2612.                 sss.loadAndRegisterSheet(uri, sss.USER_SHEET);
  2613.             }
  2614.             
  2615.             personasrotatorprefsinstance.setBoolPref("extensions.personasrotator.rotationenabled",true);
  2616.         },    
  2617.         
  2618.         changeMenuOptionForDisableRotation:function(){
  2619.             
  2620.             var personasrotatorprefsinstance = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);        
  2621.             var rotationenabled = personasrotatorprefsinstance.getBoolPref("extensions.personasrotator.rotationenabled");
  2622.  
  2623.             var sss = Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService);
  2624.             var ios = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);
  2625.             var css = "@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);#personasrotator-"+("disable")+"rotation{display:none !important;}";
  2626.             var css2 = "@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);#personasrotator-"+("enable")+"rotation{display:none !important;}";
  2627.             var uri = ios.newURI("data:text/css," + css, null, null);
  2628.             var uri2 = ios.newURI("data:text/css," + css2, null, null);
  2629.             
  2630.             if (sss.sheetRegistered(uri2, sss.USER_SHEET)) {
  2631.                 sss.unregisterSheet(uri2, sss.USER_SHEET);
  2632.             }
  2633.             
  2634.             if (!sss.sheetRegistered(uri, sss.USER_SHEET)) {
  2635.                 sss.loadAndRegisterSheet(uri, sss.USER_SHEET);
  2636.             }
  2637.             
  2638.             personasrotatorprefsinstance.setBoolPref("extensions.personasrotator.rotationenabled",false);
  2639.         
  2640.         },
  2641.                 
  2642.         disableRotation:function(source){
  2643.             
  2644.             if(source==null) PersonasRotator.changeMenuOptionForDisableRotation();
  2645.             
  2646.             PersonasRotator.PR.cancelTimer();
  2647.  
  2648.         },
  2649.         
  2650.         updateRotationInterval:function(passedTime){
  2651.  
  2652.             PersonasRotator.PR.cancelTimer();
  2653.             PersonasRotator.PR.initializeTimer(passedTime,true);
  2654.  
  2655.         },
  2656.         
  2657.         previewThePersonaOnDesktop:function(previewRequestObject){
  2658.         
  2659.             PersonasRotator.disableRotation("web");
  2660.             
  2661.             if(PersonasRotator.previewTimer!=null) PersonasRotator.previewTimer.cancel();
  2662.             
  2663.             PersonasRotator.changeDesktopPersona(previewRequestObject);
  2664.             
  2665.             //show for 30 seconds
  2666.             
  2667.             var event = { 
  2668.          
  2669.                 notify: function(timer) { 
  2670.  
  2671.                     var personasrotatorprefsinstance = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);        
  2672.                     var rotationenabled = personasrotatorprefsinstance.getBoolPref("extensions.personasrotator.rotationenabled");
  2673.                         
  2674.                     if(rotationenabled){    
  2675.                     
  2676.                         PersonasRotator.changeDesktopPersona();
  2677.                     
  2678.                         PersonasRotator.enableRotation("web");
  2679.                     
  2680.                     }
  2681.                 
  2682.                 }
  2683.        
  2684.             }
  2685.  
  2686.             PersonasRotator.previewTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
  2687.  
  2688.             PersonasRotator.previewTimer.initWithCallback(event,30000,Components.interfaces.nsITimer.TYPE_ONE_SHOT);        
  2689.         
  2690.         },
  2691.         
  2692.         retrieveBackgroundColor: function (passedColor){
  2693.             var color = parseInt(passedColor);
  2694.             const rMask = 4294901760;
  2695.             const gMask = 65280;
  2696.             const bMask = 255;
  2697.             var r = (color & rMask) >> 16;
  2698.             var g = (color & gMask) >> 8;
  2699.             var b = (color & bMask);
  2700.             return (PersonasRotator.rgbToHex(r, g, b));
  2701.         },
  2702.         
  2703.         rgbToHex: function (aR, aG, aB){
  2704.             return "#" + [aR, aG, aB].map(function(aInt) aInt.toString(16).replace(/^(.)$/, "0$1")).join("").toUpperCase();
  2705.         }                
  2706.     
  2707.     }
  2708.     
  2709.     //when we copy the personasrotator directory, this should be uncommented.
  2710.     //PersonasRotator.preload();
  2711.  
  2712.     //PersonasRotator.bringPersonas();
  2713.  
  2714.     //URLBarSetURI = PersonasRotator.newURLBarSetURI;
  2715.     
  2716.     window.addEventListener("load",PersonasRotator.mainWindowLoadHandler,false);